home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 September (Japanese) / CICA Shareware for Windows CD-ROM (Walnut Creek) (September 1995) (Japanese) (Disc 2).iso / disc2 / patches / symantec / mfcsim.exe / SIMNEW.EXE / MFC / SAMPLES / DIB / SERVICE.WMC < prev    next >
Encoding:
Text File  |  1993-10-06  |  103.8 KB  |  3,921 lines

  1. // Filename: SERVICE.WMC                                    
  2. // "DIB" Generated by Visual Programmer.                    
  3. // Author:   Blue Sky                                       
  4.  
  5. // 
  6. // ***********************************************************************
  7. // Do not add code here. Add code in the .CPP file.
  8. // 
  9. // This file is maintained by the Switch-It Module.
  10. // As you make changes in your applications design,
  11. // this file is automatically updated, therefore you never modify this file.
  12. // 
  13. // 
  14. // 
  15. // For more information,
  16. // see the section "How code is generated" in the documentation.
  17. // 
  18. // ***********************************************************************
  19. // 
  20.  
  21.  
  22. // ********************************************************
  23. //  ERROR MESSAGE HANDLING
  24. // ********************************************************
  25.  
  26. int BLDDisplayMessageDef(HWND hWnd,UINT uMsg,char *pContext,int iType)
  27.     { 
  28.     int         i, j; 
  29.     char        szMessage[200+1]; 
  30.  
  31.     if (uMsg) 
  32.         { 
  33.         if (!LoadString(AfxGetResourceHandle(),uMsg,szMessage,200)) 
  34.             { 
  35.             MessageBox(hWnd,BLDLOADERROR,BLDMAINCAPTION, 
  36.                        MB_OK|MB_SYSTEMMODAL|MB_ICONHAND); 
  37.             return FALSE; 
  38.             } 
  39.         } 
  40.     else 
  41.         szMessage[0]=0; 
  42.  
  43.     if (pContext) 
  44.         { 
  45.         i = lstrlen(szMessage); 
  46.         j = lstrlen(pContext); 
  47.         if (i + j + 1 <= 200) 
  48.             { 
  49.             lstrcat(szMessage, " "); 
  50.             lstrcat(szMessage, pContext); 
  51.             } 
  52.         } 
  53.  
  54.     return MessageBox(hWnd,szMessage,BLDMAINCAPTION,iType); 
  55.     } 
  56.  
  57.  
  58. // *************************************************************
  59. //          FUNCTIONS FOR DRAWING GRAPHIC BUTTONS
  60. // *************************************************************
  61.  
  62.  
  63. BOOL BLDBitmapToScreenDef(HDC hDestDC, char *pBitmapName,
  64.     int X,int Y,int nWidth,int nHeight,
  65.     DWORD dwRop,BOOL bStretch)
  66.     {
  67.     HDC          hMemDC;
  68.     BITMAP       Bitmap;
  69.     HBITMAP      hBitmap;
  70.  
  71.     if (!hBMPInst)
  72.         hBMPInst = AfxGetResourceHandle();
  73.  
  74.     hBitmap = BLDLoadBitmap(hBMPInst,pBitmapName);
  75.  
  76.     if (!hBitmap)
  77.         {
  78.         BLDDisplayMessage(GetActiveWindow(),BLD_CannotLoadBitmap,pBitmapName,
  79.                           MB_OK | MB_ICONASTERISK);
  80.         return FALSE;
  81.         }
  82.  
  83.     hMemDC = CreateCompatibleDC(hDestDC);
  84.  
  85.     if (!hMemDC)
  86.         {
  87.         DeleteObject(hBitmap);
  88.         return FALSE;
  89.         }
  90.     if (!SelectObject(hMemDC,hBitmap))
  91.         {
  92.         DeleteObject(hBitmap);
  93.         DeleteDC(hMemDC);
  94.         return FALSE;
  95.         }
  96.  
  97.     if (bStretch)
  98.         {
  99.         if (!GetObject(hBitmap,sizeof(BITMAP),(LPSTR)&Bitmap))
  100.             {
  101.             DeleteObject(hBitmap);
  102.             return FALSE;
  103.             }
  104.  
  105.         StretchBlt(hDestDC,
  106.             X,
  107.             Y,
  108.             nWidth,
  109.             nHeight,
  110.             hMemDC,
  111.             0,
  112.             0,
  113.             Bitmap.bmWidth,
  114.             Bitmap.bmHeight,
  115.             dwRop);
  116.         }
  117.     else
  118.         {
  119.         BitBlt(hDestDC,X,Y,nWidth,nHeight,hMemDC,0,0,dwRop);
  120.         }
  121.  
  122.     DeleteDC(hMemDC);
  123.     DeleteObject(hBitmap);
  124.     return TRUE;
  125.     }
  126.  
  127.  
  128.  
  129. BOOL BLDDrawIconDef(LPDRAWITEMSTRUCT lpDrawItem,char *pIconName)
  130.     {
  131.     HICON       hIcon;
  132.  
  133.     hIcon = LoadIcon(AfxGetResourceHandle(),pIconName);
  134.     if (!hIcon)
  135.         {
  136.         BLDDisplayMessage(GetActiveWindow(),BLD_CannotLoadIcon,pIconName,
  137.                           MB_OK | MB_ICONASTERISK);
  138.         return FALSE;
  139.         }
  140.     
  141.     SetMapMode(lpDrawItem->hDC,MM_TEXT);
  142.     return DrawIcon(lpDrawItem->hDC,0,0,hIcon);
  143.     }
  144.  
  145.  
  146.  
  147. BOOL BLDDrawBitmapDef(LPDRAWITEMSTRUCT lpDrawItem,char *pBitmapName,BOOL bStretch)
  148.     {
  149.     int        iRaster;
  150.  
  151.     iRaster = GetDeviceCaps(lpDrawItem->hDC,RASTERCAPS);
  152.     if ((iRaster&RC_BITBLT)!=RC_BITBLT)
  153.         return FALSE; //  Device cannot display bitmap 
  154.  
  155.     return BLDBitmapToScreen(lpDrawItem->hDC,pBitmapName,
  156.                   lpDrawItem->rcItem.left,
  157.                   lpDrawItem->rcItem.top,
  158.                   lpDrawItem->rcItem.right-lpDrawItem->rcItem.left,
  159.                   lpDrawItem->rcItem.bottom-lpDrawItem->rcItem.top,
  160.                   SRCCOPY,bStretch);
  161.     }
  162.  
  163.  
  164.  
  165. BOOL BLDDrawBkgndIconDef(HWND hDlg,LPPAINTSTRUCT pPs,char *pIconName,int iCtrlID)
  166.     {
  167.     RECT        Rect,Dummy;
  168.     HWND        CtrlhWnd;
  169.     HICON       hIcon;
  170.  
  171.     CtrlhWnd=GetDlgItem(hDlg,iCtrlID);
  172.     if(!CtrlhWnd)
  173.         return FALSE;
  174.     GetWindowRect(CtrlhWnd, &Rect);
  175.     ScreenToClient(hDlg,(LPPOINT)&Rect.left);
  176.     ScreenToClient(hDlg,(LPPOINT)&Rect.right);
  177.  
  178.     hIcon = LoadIcon(AfxGetResourceHandle(),pIconName);
  179.     if (!hIcon)
  180.         {
  181.         BLDDisplayMessage(GetActiveWindow(),BLD_CannotLoadIcon,pIconName,
  182.                           MB_OK | MB_ICONASTERISK);
  183.         return FALSE;
  184.         }
  185.  
  186.     if(!IntersectRect(&Dummy, &Rect, &pPs->rcPaint))
  187.         return TRUE; //  No intersection 
  188.  
  189.     SetMapMode(pPs->hdc,MM_TEXT);
  190.     return DrawIcon(pPs->hdc,Rect.left,Rect.top,hIcon);
  191.     }
  192.  
  193.  
  194.  
  195. BOOL BLDDrawBkgndBitmapDef(HWND hDlg,LPPAINTSTRUCT pPs,char *pBitmapName,
  196.        int iCtrlID,BOOL bStretch,BOOL bCtrl,int xScrolled,int yScrolled)
  197.     {
  198.     int         iRaster;
  199.     RECT        Rect,Dummy;
  200.     HWND        CtrlhWnd;
  201.  
  202.     iRaster = GetDeviceCaps(pPs->hdc,RASTERCAPS);
  203.     if ((iRaster&RC_BITBLT)!=RC_BITBLT)
  204.         return FALSE; //  Device cannot display bitmap 
  205.  
  206.     if(bCtrl)
  207.         {
  208.         CtrlhWnd=GetDlgItem(hDlg,iCtrlID);
  209.         if(!CtrlhWnd)
  210.             return FALSE;
  211.         GetWindowRect(CtrlhWnd, &Rect);
  212.         ScreenToClient(hDlg,(LPPOINT)&Rect.left);
  213.         ScreenToClient(hDlg,(LPPOINT)&Rect.right);
  214.         }
  215.     else
  216.         {
  217.         GetClientRect(hDlg, &Rect);
  218.         if(!bStretch)
  219.             {
  220.             Rect.left  -= xScrolled;
  221.             Rect.top   -= yScrolled;
  222.             }
  223.         }
  224.  
  225.     if(!IntersectRect(&Dummy, &Rect, &pPs->rcPaint))
  226.         return TRUE; //  No intersection 
  227.  
  228.     return BLDBitmapToScreen(pPs->hdc,pBitmapName,
  229.                         Rect.left,
  230.                         Rect.top,
  231.                         Rect.right-Rect.left,
  232.                         Rect.bottom-Rect.top,
  233.                         SRCCOPY,bStretch);
  234.     }
  235.  
  236.  
  237.  
  238. BOOL BLDDrawAutoStateDef(LPDRAWITEMSTRUCT lpDrawItem,char *szResource,BOOL bBitmap,
  239.                          BOOL bStretch)
  240.     {
  241.     int         x,y,dx,dy;
  242.     BOOL        bDown,bActive;
  243.     HBRUSH      hOldBrush;
  244.     int         incr,i,j,bGray;
  245.     COLORREF    color;
  246.     HICON       hIcon;
  247.  
  248.     if (lpDrawItem->CtlType != ODT_BUTTON)
  249.         return FALSE;
  250.  
  251.     if ((lpDrawItem->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) == 0)
  252.         return FALSE;
  253.  
  254.     bDown   = (lpDrawItem->itemState & ODS_SELECTED) != 0;
  255.     bActive = (lpDrawItem->itemState & ODS_DISABLED) == 0;
  256.  
  257.     x  = lpDrawItem->rcItem.left;
  258.     y  = lpDrawItem->rcItem.top;
  259.     dx = lpDrawItem->rcItem.right-lpDrawItem->rcItem.left-6;
  260.     dy = lpDrawItem->rcItem.bottom-lpDrawItem->rcItem.top-6;
  261.  
  262.     incr = bDown ? 4 : 3;
  263.  
  264.     if(!*szResource)
  265.         {
  266.         hOldBrush = (HBRUSH)SelectObject(lpDrawItem->hDC,GetStockObject(LTGRAY_BRUSH));
  267.         PatBlt(lpDrawItem->hDC, x+incr, y+incr, dx, dy, PATCOPY);
  268.         SelectObject(lpDrawItem->hDC,hOldBrush);
  269.         }
  270.     else
  271.         {
  272.         if(bBitmap)
  273.             {
  274.             if(!BLDBitmapToScreen(lpDrawItem->hDC,szResource,
  275.                               x+incr,
  276.                               y+incr,
  277.                               dx,
  278.                               dy,
  279.                               SRCCOPY,bStretch))
  280.                 return FALSE;
  281.             }
  282.         else
  283.             {
  284.             hIcon=LoadIcon(AfxGetResourceHandle(),szResource);
  285.             if (!hIcon)
  286.                 return FALSE;
  287.             DrawIcon(lpDrawItem->hDC,x+incr,y+incr,hIcon);
  288.             }
  289.         }
  290.  
  291.     //  Make the bitmap grayed 
  292.     if (!bActive)
  293.         {
  294.         color = BLD_LTGRAY;
  295.  
  296.         for (j=y+incr; j<dy; ++j)
  297.             {
  298.             bGray = j % 2;
  299.             for (i=x+incr; i<dx; ++i)
  300.                 {
  301.                 if (bGray)
  302.                     SetPixel(lpDrawItem->hDC, i, j, color);
  303.                 bGray = !bGray;
  304.                 }
  305.             }
  306.         }
  307.  
  308.     return BLDDrawFrame(lpDrawItem->hDC,x,y,dx,dy,bDown);
  309.     }
  310.  
  311.  
  312.  
  313. BOOL BLDDrawStateBitmapDef(LPDRAWITEMSTRUCT lpDrawItem,char *szNormal,char *szFocus,
  314.                            char *szSelected,char *szDisabled,BOOL bStretch)
  315.     {
  316.     if( !*szFocus && !*szSelected && !*szDisabled)
  317.         {
  318.         return BLDDrawAutoState(lpDrawItem, szNormal, TRUE, bStretch);
  319.         }
  320.     if((lpDrawItem->itemState & ODS_DISABLED) && *szDisabled)
  321.         return BLDDrawBitmap(lpDrawItem,szDisabled,bStretch);
  322.     if((lpDrawItem->itemState & ODS_SELECTED) && *szSelected)
  323.         return BLDDrawBitmap(lpDrawItem,szSelected,bStretch);
  324.     if((lpDrawItem->itemState & ODS_FOCUS) && *szFocus)
  325.         return BLDDrawBitmap(lpDrawItem,szFocus,bStretch);
  326.     if(*szNormal)
  327.         return BLDDrawBitmap(lpDrawItem,szNormal,bStretch);
  328.     return TRUE;
  329.     }
  330.  
  331.  
  332.  
  333. BOOL BLDDrawStateIconDef(LPDRAWITEMSTRUCT lpDrawItem,char *szNormal,char *szFocus,
  334.                          char *szSelected,char *szDisabled)
  335.     {
  336.     if( !*szFocus && !*szSelected && !*szDisabled)
  337.         {
  338.         return BLDDrawAutoState(lpDrawItem, szNormal, FALSE, FALSE);
  339.         }
  340.     if((lpDrawItem->itemState & ODS_DISABLED) && *szDisabled)
  341.         return BLDDrawIcon(lpDrawItem,szDisabled);
  342.     if((lpDrawItem->itemState & ODS_SELECTED) && *szSelected)
  343.         return BLDDrawIcon(lpDrawItem,szSelected);
  344.     if((lpDrawItem->itemState & ODS_FOCUS) && *szFocus)
  345.         return BLDDrawIcon(lpDrawItem,szFocus);
  346.     if(*szNormal)
  347.         return BLDDrawIcon(lpDrawItem,szNormal);
  348.     return TRUE;
  349.     }
  350.  
  351.  
  352.  
  353. BOOL BLDDrawItemDef(HWND hDlg,LPDRAWITEMSTRUCT lpDrawItem)
  354.     {
  355.     char szStr[20];
  356.  
  357.     if(lpDrawItem->CtlType == ODT_BUTTON)
  358.         {
  359.         GetWindowText(lpDrawItem->hwndItem,szStr,20);
  360.         if(lstrcmpi( (LPSTR)szStr, (LPSTR)"WMP3DBUTTON") == 0 )
  361.             {
  362.             BLDDrawStateBitmap(lpDrawItem,"","","","",TRUE);
  363.             return TRUE;
  364.             }
  365.         }
  366.     return FALSE;
  367.     }
  368.  
  369.  
  370. BOOL BLDDrawFrame(HDC hDC,int x,int y,int dx,int dy,BOOL bDown)
  371.     {
  372.     HPEN        hOld,hBlack,hLtGray,hGray,hWhite;
  373.  
  374.     hBlack  = CreatePen(0,1,BLD_BLACK);
  375.     hGray   = CreatePen(0,1,GetDeviceCaps(hDC, NUMCOLORS) > 2 ? BLD_GRAY : BLD_WHITE);
  376.     hWhite  = CreatePen(0,1,BLD_WHITE);
  377.     hLtGray = CreatePen(0,1,GetDeviceCaps(hDC, NUMCOLORS) > 2 ? BLD_LTGRAY : BLD_WHITE);
  378.  
  379.     //  Paint the frame 
  380.     hOld = (HPEN)SelectObject(hDC, hBlack);
  381.     BLDMoveTo(hDC,x+1,y);
  382.     LineTo(hDC, x+dx+5, y);
  383.     BLDMoveTo(hDC,x+1,y+dy+5);
  384.     LineTo(hDC, x+dx+5, y+dy+5);
  385.  
  386.     BLDMoveTo(hDC,x,y+1);
  387.     LineTo(hDC, x, y+dy+5);
  388.     BLDMoveTo(hDC,x+dx+5,y+1);
  389.     LineTo(hDC, x+dx+5, y+dy+5);
  390.  
  391.     if (bDown)
  392.         {
  393.         BLDMoveTo(hDC,x+1,y+1);
  394.         LineTo(hDC, x+dx+5, y+1);
  395.         BLDMoveTo(hDC,x+1,y+2);
  396.         LineTo(hDC, x+1, y+dy+5);
  397.         BLDMoveTo(hDC,x+dx+4,y+dy+4);
  398.         LineTo(hDC, x, y+dy+4);
  399.         BLDMoveTo(hDC,x+dx+4,y+dy+3);
  400.         LineTo(hDC, x+dx+4, y);
  401.  
  402.         SelectObject(hDC,hGray);
  403.         BLDMoveTo(hDC,x+2,y+2);
  404.         LineTo(hDC,x+dx+4,y+2);
  405.         BLDMoveTo(hDC,x+2,y+3);
  406.         LineTo(hDC,x+2,y+dy+4);
  407.  
  408.         SelectObject(hDC,hLtGray);
  409.         BLDMoveTo(hDC,x+3,y+3);
  410.         LineTo(hDC,x+dx+4,y+3);
  411.         BLDMoveTo(hDC,x+3,y+4);
  412.         LineTo(hDC,x+3,y+dy+4);
  413.         }
  414.     else
  415.         {
  416.         SelectObject(hDC,hWhite);
  417.         BLDMoveTo(hDC,x+1,y+1);
  418.         LineTo(hDC,x+dx+4,y+1);
  419.         BLDMoveTo(hDC,x+1,y+2);
  420.         LineTo(hDC,x+1,y+dy+4);
  421.         BLDMoveTo(hDC,x+2,y+2);
  422.         LineTo(hDC,x+dx+3,y+2);
  423.         BLDMoveTo(hDC,x+2,y+3);
  424.         LineTo(hDC,x+2,y+dy+3);
  425.  
  426.  
  427.         SelectObject(hDC, hGray);
  428.         BLDMoveTo(hDC,x+dx+4,y+dy+4);
  429.         LineTo(hDC,x,y+dy+4);
  430.         BLDMoveTo(hDC,x+dx+4,y+dy+3);
  431.         LineTo(hDC,x+dx+4,y);
  432.         BLDMoveTo(hDC,x+dx+3,y+dy+3);
  433.         LineTo(hDC,x+1,y+dy+3);
  434.         BLDMoveTo(hDC,x+dx+3,y+dy+2);
  435.         LineTo(hDC,x+dx+3,y+1);
  436.         }
  437.  
  438.     SelectObject(hDC, hOld);
  439.     DeleteObject(hBlack);
  440.     DeleteObject(hWhite);
  441.     DeleteObject(hGray);
  442.     DeleteObject(hLtGray);
  443.     return TRUE;
  444.     }
  445.  
  446.  
  447. static BOOL BLDMoveTo(HDC hDC,int x,int y)
  448.     {
  449. #ifdef WIN32
  450.     return MoveToEx(hDC,x,y,NULL);
  451. #else
  452.    return (BOOL)MoveTo(hDC,x,y);
  453. #endif
  454.     }
  455.  
  456.  
  457. // *************************************************************
  458. //          FUNCTIONS FOR DIALOG BOX SCROLLING
  459. // *************************************************************
  460.  
  461. void BLDFindCtrlsRightBottomDef(CWnd *pWnd,int *xRight,int *yBottom)
  462.     {
  463.     CWnd      *pCtrlhWnd;
  464.     RECT      Rect;
  465.  
  466.     *xRight=0;
  467.     *yBottom=0;
  468.  
  469.     pCtrlhWnd = pWnd->GetWindow(GW_CHILD);
  470.  
  471.     while(pCtrlhWnd)
  472.         {
  473.         pCtrlhWnd->GetWindowRect(&Rect);
  474.         pWnd->ScreenToClient((LPPOINT)&Rect.right);
  475.         if(Rect.right > *xRight)
  476.             *xRight = Rect.right;
  477.         if(Rect.bottom > *yBottom)
  478.             *yBottom = Rect.bottom;
  479.         pCtrlhWnd = pCtrlhWnd->GetWindow(GW_HWNDNEXT);
  480.         }
  481.     }
  482.  
  483.  
  484. void BLDCalcScrollRangesDef(CWnd *pWnd,int *xRange,int *yRange,int xScrolled,
  485.                             int yScrolled,int iRightOf,int iBelow)
  486.     {
  487.     RECT        ClientRect;
  488.     int         xRight,yBottom;
  489.  
  490.     BLDFindCtrlsRightBottom(pWnd,&xRight,&yBottom);
  491.     pWnd->GetClientRect(&ClientRect);
  492.     xRight +=xScrolled+iRightOf;
  493.     yBottom+=yScrolled+iBelow;
  494.  
  495.     if(xRight - ClientRect.right > 0)
  496.         *xRange=xRight - ClientRect.right;
  497.     else
  498.         *xRange=0;
  499.     if(yBottom - ClientRect.bottom > 0)
  500.         *yRange=yBottom - ClientRect.bottom;
  501.     else
  502.         *yRange=0;
  503.     }
  504.  
  505.  
  506.  
  507. BOOL BLDScrollDlgDef(CWnd *pWnd,UINT message,int nScrlCode,int nPos,int iVertLine,
  508.                      int iHorLine,int iVertPage,int iHorPage,int iRightOf,
  509.                      int iBelow,BOOL bInvalidate,int *pxScrolled,int *pyScrolled)
  510.     {
  511.     int         xScroll,yScroll;
  512.     int         xRange,yRange;
  513.     int         iThumb;
  514.     BOOL        bDlgUnits;
  515.  
  516.  
  517.     xScroll=yScroll=0;
  518.  
  519.     BLDCalcScrollRanges(pWnd,&xRange,&yRange,*pxScrolled,*pyScrolled,iRightOf,iBelow);
  520.  
  521.     bDlgUnits=FALSE;
  522.     switch(message)
  523.         {
  524.     case WM_VSCROLL:
  525.         switch(nScrlCode)
  526.             {
  527.         case SB_BOTTOM:
  528.             yScroll=yRange-*pyScrolled;
  529.             bDlgUnits=FALSE;
  530.             break;
  531.         case SB_ENDSCROLL:
  532.             break;
  533.         case SB_LINEDOWN:
  534.             yScroll=iVertLine;
  535.             bDlgUnits=TRUE;
  536.             break;
  537.         case SB_LINEUP:
  538.             yScroll=-iVertLine;
  539.             bDlgUnits=TRUE;
  540.             break;
  541.         case SB_PAGEDOWN:
  542.             if(iVertPage)
  543.                 {
  544.                 RECT Rect;
  545.                 pWnd->GetClientRect(&Rect);
  546.                 yScroll=MulDiv(Rect.bottom,iVertPage,100);
  547.                 bDlgUnits=FALSE;
  548.                 }
  549.             break;
  550.         case SB_PAGEUP:
  551.             if(iVertPage)
  552.                 {
  553.                 RECT Rect;
  554.                 pWnd->GetClientRect(&Rect);
  555.                 yScroll=-MulDiv(Rect.bottom,iVertPage,100);
  556.                 bDlgUnits=FALSE;
  557.                 }
  558.             break;
  559.         case SB_THUMBPOSITION:
  560.             iThumb =nPos;
  561.             yScroll=-*pyScrolled + MulDiv(iThumb,yRange,100);
  562.             bDlgUnits=FALSE;
  563.             break;
  564.         case SB_THUMBTRACK:   // No Support
  565.             break;
  566.         case SB_TOP:
  567.             yScroll=-*pyScrolled;
  568.             bDlgUnits=FALSE;
  569.             break;
  570.             }
  571.         break;
  572.     case WM_HSCROLL:
  573.         switch(nScrlCode)
  574.             {
  575.         case SB_BOTTOM:
  576.             xScroll=xRange-*pxScrolled;
  577.             bDlgUnits=FALSE;
  578.             break;
  579.         case SB_ENDSCROLL:
  580.             break;
  581.         case SB_LINEDOWN:
  582.             xScroll=iHorLine;
  583.             bDlgUnits=TRUE;
  584.             break;
  585.         case SB_LINEUP:
  586.             xScroll=-iHorLine;
  587.             bDlgUnits=TRUE;
  588.             break;
  589.         case SB_PAGEDOWN:
  590.             if(iVertPage)
  591.                 {
  592.                 RECT Rect;
  593.                 pWnd->GetClientRect(&Rect);
  594.                 xScroll=MulDiv(Rect.right,iHorPage,100);
  595.                 bDlgUnits=FALSE;
  596.                 }
  597.             break;
  598.         case SB_PAGEUP:
  599.             if(iVertPage)
  600.                 {
  601.                 RECT Rect;
  602.                 pWnd->GetClientRect(&Rect);
  603.                 xScroll=-MulDiv(Rect.bottom,iHorPage,100);
  604.                 bDlgUnits=FALSE;
  605.                 }
  606.             break;
  607.         case SB_THUMBPOSITION:
  608.             iThumb =nPos;
  609.             xScroll=-*pxScrolled + MulDiv(iThumb,xRange,100);
  610.             bDlgUnits=FALSE;
  611.             break;
  612.         case SB_THUMBTRACK:   // No Support
  613.             break;
  614.         case SB_TOP:
  615.             xScroll=-*pxScrolled;
  616.             bDlgUnits=FALSE;
  617.             break;
  618.             }
  619.         break;
  620.         }
  621.  
  622.     if(xScroll || yScroll)
  623.         {
  624.         int x,y;
  625.         int oldx,oldy;
  626.  
  627.         x=y=0;
  628.         if(bDlgUnits)
  629.             {
  630.             BOOL xNeg,yNeg;
  631.             xNeg=yNeg=FALSE;
  632.             if(xScroll < 0)
  633.                 {
  634.                 xScroll=-xScroll;
  635.                 xNeg=TRUE;
  636.                 }
  637.             if(yScroll < 0)
  638.                 {
  639.                 yScroll=-yScroll;
  640.                 yNeg=TRUE;
  641.                 }
  642.             xScroll=(xScroll * LOWORD(GetDialogBaseUnits()))/4;
  643.             yScroll=(yScroll * HIWORD(GetDialogBaseUnits()))/8;
  644.             if(xNeg)
  645.                 xScroll=-xScroll;
  646.             if(yNeg)
  647.                 yScroll=-yScroll;
  648.             }
  649.  
  650.         oldx=*pxScrolled;
  651.         oldy=*pyScrolled;
  652.         *pxScrolled+=xScroll;
  653.         *pyScrolled+=yScroll;
  654.  
  655.         if(*pxScrolled > xRange)
  656.             *pxScrolled = xRange;
  657.         if(*pxScrolled < 0)
  658.             *pxScrolled=0;
  659.  
  660.         if(*pyScrolled > yRange)
  661.             *pyScrolled = yRange;
  662.         if(*pyScrolled < 0)
  663.             *pyScrolled=0;
  664.  
  665.         xScroll=*pxScrolled - oldx;
  666.         yScroll=*pyScrolled - oldy;
  667.  
  668.         if(xScroll || yScroll)
  669.             {
  670.             pWnd->ScrollWindow(-xScroll,-yScroll,NULL,NULL);
  671.             if(xRange)
  672.                 {
  673.                 x=MulDiv(*pxScrolled,100,xRange);
  674.                 pWnd->SetScrollPos(SB_HORZ,x,TRUE);
  675.                 }
  676.             if(yRange)
  677.                 {
  678.                 y=MulDiv(*pyScrolled,100,yRange);
  679.                 pWnd->SetScrollPos(SB_VERT,y,TRUE);
  680.                 }
  681.             if(bInvalidate)
  682.                 pWnd->InvalidateRect(NULL,FALSE);
  683.             }
  684.         }
  685.     return TRUE;
  686.     }
  687.  
  688.  
  689. // *************************************************************
  690. //        FUNCTION FOR CREATING CONTROLS IN MAIN WINDOW         
  691. // *************************************************************
  692.  
  693. // Supports Controls in Main window from old versions
  694. BOOL BLDCreateClientControlsDef(char *pTemplateName, CSimClientDlg* pDlg)
  695.     {
  696.  
  697.     pDlg->SimSetTemplate(pTemplateName); //Set template. Constructor
  698.                                          //without parameters was used
  699.                                          //in earlier versions in .cpp file
  700.     if (pDlg->Create(TheApp.m_pMainWnd))
  701.         {
  702.         TheApp.pWndClient = pDlg;
  703.         return TRUE;
  704.         }
  705.     else
  706.         return FALSE;
  707.     }
  708.   
  709.   
  710. // *************************************************************
  711. //          FUNCTION SENDING MDI MESSAGES
  712. // *************************************************************
  713.   
  714. BOOL BLDSendMDIMessageDef(CWnd *pWnd,UINT message,int nType)
  715.     {
  716.     if(TheApp.m_pMainWnd->IsKindOf(RUNTIME_CLASS(CMDIFrameWnd)))
  717.         {
  718.         CMDIFrameWnd *pMDIFrameWnd = (CMDIFrameWnd *)TheApp.m_pMainWnd;
  719.         CMDIChildWnd *pCMDIChildWnd;
  720.         switch(message)
  721.             {
  722.         case WM_MDICASCADE:
  723. #if (WINVER >= 0x030a)
  724.             pMDIFrameWnd->MDICascade(nType);
  725. #else
  726.             pMDIFrameWnd->MDICascade();
  727. #endif
  728.             break;
  729.         case WM_MDITILE:
  730. #if (WINVER >= 0x030a)
  731.             pMDIFrameWnd->MDITile(nType);
  732. #else
  733.             pMDIFrameWnd->MDITile();
  734. #endif
  735.             break;
  736.         case WM_MDIICONARRANGE:
  737.             pMDIFrameWnd->MDIIconArrange();
  738.             break;
  739.         case WM_MDIGETACTIVE:
  740.             pCMDIChildWnd = pMDIFrameWnd->MDIGetActive();
  741.             if(pCMDIChildWnd)
  742.                 pCMDIChildWnd->MDIDestroy();
  743.             break;
  744.         default:
  745.             return FALSE;
  746.             }
  747.         return TRUE;
  748.         }
  749.     return FALSE;         //Not an MDI application
  750.     }
  751.  
  752.  
  753. // *************************************************************
  754. //          FUNCTION EXPANDING OF DIALOG BOX
  755. // *************************************************************
  756.  
  757. BOOL BLDSizeDlgDef(CWnd *pWnd,int xRightOf,int yBelow)
  758.     {
  759.      return (BOOL)pWnd->SendMessage(wPrivateMessage,SIM_SIZEDIALOG,
  760.                    MAKELONG(xRightOf,yBelow));
  761.     }
  762.  
  763.  
  764. // *************************************************************
  765. //          FUNCTIONS FOR HELP HANDLING
  766. // *************************************************************
  767.  
  768.  
  769. BOOL BLDCheckF1HelpKeyDef(BOOL bShift)
  770.     {
  771.     if(GetKeyState(VK_F1) >= 0)
  772.         return FALSE;
  773.     if(bShift)
  774.         {
  775.         if(GetKeyState(VK_SHIFT) >= 0)
  776.             return FALSE;
  777.         }
  778.     else
  779.         {
  780.         if(GetKeyState(VK_SHIFT) < 0)
  781.             return FALSE;
  782.         }
  783.     if(GetKeyState(VK_CONTROL) < 0)
  784.         return FALSE;
  785.     if(GetKeyState(VK_MENU) < 0)
  786.         return FALSE;
  787.     return TRUE;
  788.     }
  789.  
  790.  
  791. HBRUSH BLDGetGlobalBrushDef(HWND hCtrl,HDC hDC)
  792.     {
  793.     char   szClass[21];
  794.     static HBRUSH hGray = 0;
  795.  
  796.     if (!hCtrl)
  797.         return 0;
  798.  
  799.     if (!hGray)
  800.         hGray = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  801.  
  802.     if (!GetClassName(hCtrl,szClass,20))
  803.         return 0;
  804.  
  805.     if (lstrcmpi(szClass,"EDIT")==0)
  806.         {
  807.         if (dwDialogProp&BLDGRAY_EDIT)
  808.             goto RETGRAYBRUSH;
  809.         else
  810.             return 0;
  811.         }
  812.     if (lstrcmpi(szClass,"COMBOBOX")==0)
  813.         {
  814.         if (dwDialogProp&BLDGRAY_COMBOBOX)
  815.             goto RETGRAYBRUSH;
  816.         else
  817.             return 0;
  818.         }
  819.     if (lstrcmpi(szClass,"LISTBOX")==0)
  820.         {
  821.         if (dwDialogProp&BLDGRAY_LISTBOX)
  822.             goto RETGRAYBRUSH;
  823.         else
  824.             return 0;
  825.         }
  826.     if (lstrcmpi(szClass,"BUTTON")==0)
  827.         {
  828.         if ((dwDialogProp&BLDGRAY_BUTTON))
  829.             goto RETGRAYBRUSH;
  830.         else
  831.             return 0;
  832.         }
  833.     if (lstrcmpi(szClass,"SCROLLBAR")==0)
  834.         {
  835.         if (dwDialogProp&BLDGRAY_SCROLLBAR)
  836.             goto RETGRAYBRUSH;
  837.         else
  838.             return 0;
  839.         }
  840.     if (lstrcmpi(szClass,"STATIC")==0)
  841.         {
  842.         if (dwDialogProp&BLDGRAY_TEXT)
  843.             goto RETGRAYBRUSH;
  844.         else
  845.             return 0;
  846.         }
  847.  
  848.     return 0;
  849.  
  850. RETGRAYBRUSH:
  851.     if (hDC)
  852.         SetBkColor(hDC,RGB(192,192,192));
  853.     return hGray;
  854.     }
  855.  
  856.  
  857.  
  858. // *************************************************************
  859. // Member Functions for MODAL dialog    : CSimModalDlg
  860. // Base Class                           : CDialog
  861. // *************************************************************
  862.  
  863. CSimModalDlg::CSimModalDlg(LPCSTR lpszTemplateName,CWnd *pParentWnd)
  864.       : CDialog(lpszTemplateName,pParentWnd)
  865. {
  866.     ms_bDeleteBrush=ms_bScrollSupport=FALSE;
  867.     ms_hBrush=0;
  868.     ms_szBitmap=NULL;
  869.     ms_bAutoMenuEnable=TRUE;    // auto enable on by default
  870. }
  871.  
  872.  
  873.  
  874. CSimModalDlg::~CSimModalDlg()
  875. {
  876.     if(ms_bDeleteBrush && ms_hBrush)
  877.         DeleteObject(ms_hBrush);
  878.     ms_bDeleteBrush=FALSE;
  879.     ms_hBrush=0;
  880.     if(ms_szBitmap)
  881.         delete ms_szBitmap;
  882. }
  883.  
  884.  
  885.  
  886. LRESULT CSimModalDlg::SimHandlePrivateMessage(WPARAM wParam,LPARAM lParam)
  887. {
  888.     RECT        Rect;
  889.     RECT        OldWindowRect;
  890.     RECT        NewActualClientRect;
  891.     int         Cx,Cy,xMax,yMax;
  892.  
  893.     if(wParam != SIM_SIZEDIALOG)
  894.         return FALSE;
  895.  
  896.     BLDFindCtrlsRightBottom(this,&Cx,&Cy);
  897.  
  898.     Cx += LOWORD(lParam);
  899.     Cy += HIWORD(lParam);
  900.  
  901.     GetClientRect((LPRECT)&Rect);
  902.     if (Rect.right >= Cx && Rect.bottom >= Cy )
  903.         return TRUE;
  904.  
  905.     if(Rect.right < Cx)
  906.         Rect.right = Cx;
  907.     if(Rect.bottom < Cy)
  908.         Rect.bottom = Cy;
  909.  
  910.     GetWindowRect(&OldWindowRect);
  911.  
  912.     if(!(GetStyle() & WS_CHILD))
  913.         ClientToScreen((LPPOINT)&Rect.left);
  914.     else
  915.         GetParent()->ScreenToClient((LPPOINT)&OldWindowRect.left);
  916.  
  917.     Rect.right +=Rect.left;
  918.     Rect.bottom+=Rect.top;
  919.  
  920.     AdjustWindowRectEx(&Rect,GetStyle(),GetMenu() ? TRUE : FALSE,
  921.               GetExStyle());
  922.  
  923.     if(OldWindowRect.top != Rect.top)
  924.         {
  925.         Rect.bottom += OldWindowRect.top - Rect.top;
  926.         Rect.top     =OldWindowRect.top;
  927.         }
  928.     if(OldWindowRect.left != Rect.left)
  929.         {
  930.         Rect.right += OldWindowRect.left - Rect.left;
  931.         Rect.left   =OldWindowRect.left;
  932.         }
  933.  
  934.     xMax = GetSystemMetrics(SM_CXSCREEN);
  935.     yMax = GetSystemMetrics(SM_CYSCREEN);
  936.     if ((Rect.right-Rect.left<=xMax)&&(Rect.right>xMax))
  937.         Rect.left=xMax-(Rect.right-Rect.left);
  938.     if ((Rect.bottom-Rect.top<=yMax)&&(Rect.bottom>yMax))
  939.         Rect.top=yMax-(Rect.bottom-Rect.top);
  940.  
  941.     MoveWindow(Rect.left,Rect.top,Rect.right-Rect.left,
  942.            Rect.bottom-Rect.top,TRUE);
  943.     GetClientRect(&NewActualClientRect);
  944.  
  945.     if(NewActualClientRect.bottom != Cy)
  946.         {
  947.         Rect.bottom -= NewActualClientRect.bottom - Cy;
  948.         MoveWindow(Rect.left,Rect.top,Rect.right-Rect.left,
  949.             Rect.bottom-Rect.top,TRUE);
  950.         }
  951.     if(NewActualClientRect.right != Cx)
  952.         {
  953.         Rect.right -= NewActualClientRect.right - Cx;
  954.         MoveWindow(Rect.left,Rect.top,Rect.right-Rect.left,
  955.             Rect.bottom-Rect.top,TRUE);
  956.         }
  957.  
  958.     return TRUE;
  959.  
  960. }
  961.  
  962.  
  963.  
  964. LRESULT CSimModalDlg::OnCommandHelp(WPARAM wParam, LPARAM lParam)
  965. {
  966.     if(ms_HelpID)
  967.        {
  968.        TheApp.WinHelp(ms_HelpID);
  969.        return TRUE;
  970.        }
  971.     return CDialog::OnCommandHelp(wParam,lParam);
  972. }
  973.  
  974.  
  975.  
  976. BOOL CSimModalDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  977.     {
  978.     if(TheApp.m_bHelpMode)
  979.         {
  980.         if(!(UINT)lParam)
  981.             {
  982.             if(TheApp.MenuHelp(wParam))
  983.                 return TRUE;
  984.             }
  985.         TheApp.WinHelp(ms_HelpID);
  986.         return TRUE;
  987.         }
  988.     return CDialog::OnCommand( wParam,  lParam);
  989.     }
  990.  
  991.  
  992.  
  993. BOOL CSimModalDlg::OnSetCursor (CWnd* pWnd, UINT nHitTest, UINT message)
  994. {
  995.     if(TheApp.m_bHelpMode)
  996.         {
  997.         ::SetCursor(TheApp.m_hcurHelp);
  998.         return TRUE;
  999.         }
  1000.     return CDialog::OnSetCursor (pWnd, nHitTest, message);
  1001. }
  1002.  
  1003.  
  1004.  
  1005. void CSimModalDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1006. {
  1007.     if(ms_bScrollSupport)
  1008.         {
  1009.         ::BLDScrollDlg((CWnd *)this,WM_VSCROLL,nSBCode,nPos,ms_iScrollVertLine,
  1010.                      ms_iScrollHorLine,ms_iScrollVertPage,ms_iScrollHorPage,ms_iScrollRightOf,
  1011.                      ms_iScrollBelow,ms_bScrollInvalidate,&ms_xScrolled,&ms_yScrolled);
  1012.         }
  1013. }
  1014.  
  1015.  
  1016.  
  1017. void CSimModalDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1018. {
  1019.     if(ms_bScrollSupport)
  1020.         {
  1021.         ::BLDScrollDlg((CWnd *)this,WM_HSCROLL,nSBCode,nPos,ms_iScrollVertLine,
  1022.                      ms_iScrollHorLine,ms_iScrollVertPage,ms_iScrollHorPage,ms_iScrollRightOf,
  1023.                      ms_iScrollBelow,ms_bScrollInvalidate,&ms_xScrolled,&ms_yScrolled);
  1024.         }
  1025. }
  1026.  
  1027.  
  1028.  
  1029. void CSimModalDlg::OnPaint()
  1030. {
  1031.     PAINTSTRUCT ps;
  1032.     HWND hWnd;
  1033.  
  1034.     if(!GetUpdateRect((LPRECT)NULL))
  1035.       return;
  1036.     if(!BeginPaint((LPPAINTSTRUCT)&ps))
  1037.         return;
  1038.  
  1039.     if(ms_szBitmap)
  1040.         ::BLDDrawBkgndBitmap(GetSafeHwnd(),(LPPAINTSTRUCT)&ps,ms_szBitmap,0,ms_bStretch,FALSE,ms_xScrolled,ms_yScrolled);
  1041.  
  1042. // we use 'HWND's to avoid generation of too many temporary CWnds
  1043.     hWnd=::GetWindow(GetSafeHwnd(),GW_CHILD);
  1044.  
  1045.     while(hWnd)
  1046.         {
  1047.         ::SendMessage(hWnd,wPrivateMessage,SIM_CTRLPAINT,
  1048.            (LONG)(LPPAINTSTRUCT)&ps);
  1049.         hWnd=::GetWindow(hWnd,GW_HWNDNEXT);
  1050.         }
  1051.  
  1052.     EndPaint((LPPAINTSTRUCT)&ps);
  1053. }
  1054.  
  1055.  
  1056.  
  1057. HBRUSH CSimModalDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  1058. {
  1059.  
  1060.     if(nCtlColor == CTLCOLOR_DLG)
  1061.         {
  1062.         if(ms_hBrush)
  1063.             {
  1064.             int x,y,xScrl,yScrl;
  1065. #ifdef WIN32
  1066.             POINT p;
  1067. #else
  1068.             CPoint p;
  1069. #endif
  1070.  
  1071.             if(ms_bScrollSupport)
  1072.                 {
  1073.                 yScrl = ms_yScrolled;
  1074.                 xScrl = ms_xScrolled;
  1075.                 }
  1076.             else
  1077.                 yScrl=yScrl=0;
  1078.             UnrealizeObject(ms_hBrush);
  1079.  
  1080. #ifdef WIN32
  1081.             ::GetBrushOrgEx(pDC->GetSafeHdc(),&p);
  1082.             x=p.x;
  1083.             y=p.y;
  1084. #else
  1085.             p=pDC->GetBrushOrg();
  1086.             x=p.x;
  1087.             y=p.y;
  1088. #endif
  1089.  
  1090.             xScrl=-xScrl+x;
  1091.             yScrl=-yScrl+y;
  1092. #ifdef WIN32
  1093.             ::SetBrushOrgEx(pDC->GetSafeHdc(),xScrl,yScrl,NULL);
  1094. #else
  1095.             pDC->SetBrushOrg(xScrl,yScrl);
  1096. #endif
  1097.             ::SelectObject(pDC->GetSafeHdc(),ms_hBrush);//Assertion failed
  1098.                                                       //when using pDC->SelectObject
  1099.             return ms_hBrush;
  1100.             }
  1101.         }
  1102.     else
  1103.         {
  1104.         HBRUSH hBrushret;
  1105. #ifdef WIN32
  1106.         hBrushret=(HBRUSH)pWnd->SendMessage(wPrivateMessage,SIM_CTLCOLOR,(LPARAM)pDC->m_hDC);
  1107. #else
  1108.         hBrushret=(HBRUSH)LOWORD(pWnd->SendMessage(wPrivateMessage,SIM_CTLCOLOR,MAKELONG(pDC->m_hDC,0)));
  1109. #endif
  1110.         if(hBrushret)
  1111.             return hBrushret;
  1112.         }
  1113.     if(dwDialogProp&BLDGRAY_DIALOGBOX)
  1114.         {
  1115.         switch (nCtlColor)
  1116.             {
  1117.         case CTLCOLOR_LISTBOX:
  1118.         case CTLCOLOR_MSGBOX:
  1119.             {
  1120.             HBRUSH hBrushret;
  1121.             hBrushret=BLDGetGlobalBrushDef(pWnd->GetSafeHwnd(),pDC->GetSafeHdc());
  1122.             if(hBrushret)
  1123.                 return hBrushret;
  1124.             else
  1125.                 return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1126.             }
  1127.             break;
  1128.         case CTLCOLOR_EDIT:
  1129.             if (!(dwDialogProp&BLDGRAY_EDIT))
  1130.                 return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1131.             break;
  1132.         case CTLCOLOR_BTN:
  1133.             if (!(dwDialogProp&BLDGRAY_BUTTON))
  1134.                 return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1135.             break;
  1136.         case CTLCOLOR_SCROLLBAR:
  1137.             if (!(dwDialogProp&BLDGRAY_SCROLLBAR))
  1138.                 return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1139.             break;
  1140.         case CTLCOLOR_STATIC:
  1141.             if (!(dwDialogProp&BLDGRAY_TEXT))
  1142.                 return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1143.              break;
  1144.         case CTLCOLOR_DLG:
  1145.             break;
  1146.         default:
  1147.             return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1148.             break;
  1149.             }
  1150.         pDC->SetBkColor(RGB(192,192,192));
  1151.         return (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  1152.         }
  1153.     return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1154.     }
  1155.  
  1156.  
  1157.  
  1158. //For default processing of WM_DRAWITEM
  1159. LRESULT CSimModalDlg::DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
  1160. {
  1161.     if(nMsg == WM_DRAWITEM)
  1162.         {
  1163.         char szStr[20];
  1164.         LPDRAWITEMSTRUCT lpDrawItem = (LPDRAWITEMSTRUCT)lParam;
  1165.         if(lpDrawItem->CtlType == ODT_BUTTON)
  1166.             {
  1167.             ::GetWindowText(lpDrawItem->hwndItem,szStr,20);
  1168.             if(lstrcmpi( (LPSTR)szStr, (LPSTR)"WMP3DBUTTON") == 0 )
  1169.                 {
  1170.                 BLDDrawStateBitmap(lpDrawItem,"","","","",TRUE);
  1171.                 return TRUE;
  1172.                 }
  1173.             }
  1174.         }
  1175.     return CDialog::DefWindowProc(nMsg,wParam,lParam);
  1176. }
  1177.  
  1178.  
  1179.  
  1180. //To support menues in dialogboxes
  1181. BOOL CSimModalDlg::OnCmdMsg(UINT nID, int nCode, void* pExtra,
  1182.     AFX_CMDHANDLERINFO* pHandlerInfo)
  1183. {
  1184.     //Control command handling ?
  1185.     if (CDialog::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
  1186.         return TRUE;
  1187.  
  1188.     // if not, pump through app
  1189.     CWinApp* pApp = AfxGetApp();
  1190.     if (pApp != NULL &&
  1191.       pApp->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
  1192.         return TRUE;
  1193.  
  1194.     return FALSE;
  1195. }
  1196.  
  1197.  
  1198. //This function is from MFC source for class 'CFrameWnd' to
  1199. //support enabling and disabling of menuitems in dialogboxes
  1200. void CSimModalDlg::OnInitMenuPopup(CMenu* pMenu, UINT, BOOL bSysMenu)
  1201. {
  1202.  
  1203.     if (bSysMenu)
  1204.         return;     // don't support system menu
  1205.  
  1206.     if(pMenu == NULL)
  1207.         return;
  1208.  
  1209.     // check the enabled state of various menu items
  1210.     CCmdUI state;
  1211.     state.m_pMenu = pMenu;
  1212.  
  1213.     state.m_nIndexMax = pMenu->GetMenuItemCount();
  1214.     for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
  1215.       state.m_nIndex++)
  1216.     {
  1217.         state.m_nID = pMenu->GetMenuItemID(state.m_nIndex);
  1218.         if (state.m_nID == 0)
  1219.             continue; // menu separator or invalid cmd - ignore it
  1220.  
  1221.         if (state.m_nID == (UINT)-1)
  1222.         {
  1223.             // possibly a popup menu, route to first item of that popup
  1224.             state.m_pSubMenu = pMenu->GetSubMenu(state.m_nIndex);
  1225.             if (state.m_pSubMenu == NULL ||
  1226.                 (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
  1227.                 state.m_nID == (UINT)-1)
  1228.             {
  1229.                 continue;       // first item of popup can't be routed to
  1230.             }
  1231.             state.DoUpdate(this, FALSE);    // popups are never auto disabled
  1232.         }
  1233.         else
  1234.         {
  1235.             // normal menu item
  1236.             // Auto enable/disable if frame window has 'm_bAutoMenuEnable'
  1237.             //    set and command is _not_ a system command.
  1238.             state.m_pSubMenu = NULL;
  1239.             state.DoUpdate(this, ms_bAutoMenuEnable && state.m_nID < 0xF000);
  1240.         }
  1241.     }
  1242. }
  1243.  
  1244.  
  1245.  
  1246. LRESULT CSimModalDlg::OnHelpHitTest(WPARAM wParam, LPARAM lParam)
  1247. {
  1248.     if(ms_HelpID)
  1249.         return ms_HelpID;
  1250.     return CSimModalDlg::OnHelpHitTest(wParam, lParam);
  1251. }
  1252.  
  1253.  
  1254.  
  1255. IMPLEMENT_DYNCREATE(CSimModalDlg, CDialog)
  1256.  
  1257. BEGIN_MESSAGE_MAP(CSimModalDlg, CDialog)
  1258.  
  1259.    ON_WM_CTLCOLOR()
  1260.    ON_WM_PAINT()
  1261.    ON_WM_HSCROLL()
  1262.    ON_WM_VSCROLL()
  1263.    ON_WM_INITMENUPOPUP()
  1264.    ON_MESSAGE(WM_HELPHITTEST, OnHelpHitTest)
  1265.    ON_REGISTERED_MESSAGE(wPrivateMessage,SimHandlePrivateMessage)
  1266.     ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
  1267.     ON_WM_SETCURSOR()
  1268.  
  1269. END_MESSAGE_MAP()
  1270.  
  1271.  
  1272.  
  1273. // *************************************************************
  1274. // Member Functions for MODELESS dialog : CSimModelessDlg
  1275. // Base Class                           : CDialog
  1276. // *************************************************************
  1277.  
  1278. CSimModelessDlg::CSimModelessDlg()
  1279.       : CDialog()
  1280. {
  1281.     ms_bDeleteBrush=ms_bScrollSupport=FALSE;
  1282.     ms_hBrush=0;
  1283.     ms_szBitmap=NULL;
  1284.     ms_bAutoMenuEnable=TRUE;    // auto enable on by default
  1285. }
  1286.  
  1287.  
  1288.  
  1289. CSimModelessDlg::~CSimModelessDlg()
  1290. {
  1291.     if(ms_bDeleteBrush && ms_hBrush)
  1292.         DeleteObject(ms_hBrush);
  1293.     ms_bDeleteBrush=FALSE;
  1294.     ms_hBrush=0;
  1295.     if(ms_szBitmap)
  1296.         delete ms_szBitmap;
  1297. }
  1298.  
  1299.  
  1300.  
  1301. void CSimModelessDlg::PostNcDestroy()
  1302. {
  1303.     delete this;
  1304. }
  1305.  
  1306.  
  1307.  
  1308. void CSimModelessDlg::OnOK()
  1309. {
  1310.     if (UpdateData(TRUE))
  1311.         DestroyWindow();
  1312. }
  1313.  
  1314.  
  1315.  
  1316. void CSimModelessDlg::OnCancel()
  1317. {
  1318.     DestroyWindow();
  1319. }
  1320.  
  1321.  
  1322.  
  1323. LRESULT CSimModelessDlg::SimHandlePrivateMessage(WPARAM wParam,LPARAM lParam)
  1324. {
  1325.     RECT        Rect;
  1326.     RECT        OldWindowRect;
  1327.     RECT        NewActualClientRect;
  1328.     int         Cx,Cy,xMax,yMax;
  1329.  
  1330.     if(wParam != SIM_SIZEDIALOG)
  1331.         return FALSE;
  1332.  
  1333.     BLDFindCtrlsRightBottom(this,&Cx,&Cy);
  1334.  
  1335.     Cx += LOWORD(lParam);
  1336.     Cy += HIWORD(lParam);
  1337.  
  1338.     GetClientRect((LPRECT)&Rect);
  1339.     if (Rect.right >= Cx && Rect.bottom >= Cy )
  1340.         return TRUE;
  1341.  
  1342.     if(Rect.right < Cx)
  1343.         Rect.right = Cx;
  1344.     if(Rect.bottom < Cy)
  1345.         Rect.bottom = Cy;
  1346.  
  1347.     GetWindowRect(&OldWindowRect);
  1348.  
  1349.     if(!(GetStyle() & WS_CHILD))
  1350.         ClientToScreen((LPPOINT)&Rect.left);
  1351.     else
  1352.         GetParent()->ScreenToClient((LPPOINT)&OldWindowRect.left);
  1353.  
  1354.     Rect.right +=Rect.left;
  1355.     Rect.bottom+=Rect.top;
  1356.  
  1357.     AdjustWindowRectEx(&Rect,GetStyle(),GetMenu() ? TRUE : FALSE,
  1358.               GetExStyle());
  1359.  
  1360.     if(OldWindowRect.top != Rect.top)
  1361.         {
  1362.         Rect.bottom += OldWindowRect.top - Rect.top;
  1363.         Rect.top     =OldWindowRect.top;
  1364.         }
  1365.     if(OldWindowRect.left != Rect.left)
  1366.         {
  1367.         Rect.right += OldWindowRect.left - Rect.left;
  1368.         Rect.left   =OldWindowRect.left;
  1369.         }
  1370.  
  1371.     xMax = GetSystemMetrics(SM_CXSCREEN);
  1372.     yMax = GetSystemMetrics(SM_CYSCREEN);
  1373.     if ((Rect.right-Rect.left<=xMax)&&(Rect.right>xMax))
  1374.         Rect.left=xMax-(Rect.right-Rect.left);
  1375.     if ((Rect.bottom-Rect.top<=yMax)&&(Rect.bottom>yMax))
  1376.         Rect.top=yMax-(Rect.bottom-Rect.top);
  1377.  
  1378.     MoveWindow(Rect.left,Rect.top,Rect.right-Rect.left,
  1379.            Rect.bottom-Rect.top,TRUE);
  1380.     GetClientRect(&NewActualClientRect);
  1381.  
  1382.     if(NewActualClientRect.bottom != Cy)
  1383.         {
  1384.         Rect.bottom -= NewActualClientRect.bottom - Cy;
  1385.         MoveWindow(Rect.left,Rect.top,Rect.right-Rect.left,
  1386.             Rect.bottom-Rect.top,TRUE);
  1387.         }
  1388.     if(NewActualClientRect.right != Cx)
  1389.         {
  1390.         Rect.right -= NewActualClientRect.right - Cx;
  1391.         MoveWindow(Rect.left,Rect.top,Rect.right-Rect.left,
  1392.             Rect.bottom-Rect.top,TRUE);
  1393.         }
  1394.  
  1395.     return TRUE;
  1396.  
  1397. }
  1398.  
  1399.  
  1400.  
  1401. LRESULT CSimModelessDlg::OnCommandHelp(WPARAM wParam, LPARAM lParam)
  1402. {
  1403.     if(ms_HelpID)
  1404.        {
  1405.        TheApp.WinHelp(ms_HelpID);
  1406.        return TRUE;
  1407.        }
  1408.     return CDialog::OnCommandHelp(wParam,lParam);
  1409. }
  1410.  
  1411.  
  1412.  
  1413. BOOL CSimModelessDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  1414.     {
  1415.     if(TheApp.m_bHelpMode)
  1416.         {
  1417.         if(!(UINT)lParam)
  1418.             {
  1419.             if(TheApp.MenuHelp(wParam))
  1420.                 return TRUE;
  1421.             }
  1422.         TheApp.WinHelp(ms_HelpID);
  1423.         return TRUE;
  1424.         }
  1425.     return CDialog::OnCommand( wParam,  lParam);
  1426.     }
  1427.  
  1428.  
  1429.  
  1430. BOOL CSimModelessDlg::OnSetCursor (CWnd* pWnd, UINT nHitTest, UINT message)
  1431. {
  1432.     if(TheApp.m_bHelpMode)
  1433.         {
  1434.         ::SetCursor(TheApp.m_hcurHelp);
  1435.         return TRUE;
  1436.         }
  1437.     return CDialog::OnSetCursor (pWnd, nHitTest, message);
  1438. }
  1439.  
  1440.  
  1441.  
  1442. void CSimModelessDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1443. {
  1444.     if(ms_bScrollSupport)
  1445.         {
  1446.         ::BLDScrollDlg((CWnd *)this,WM_VSCROLL,nSBCode,nPos,ms_iScrollVertLine,
  1447.                      ms_iScrollHorLine,ms_iScrollVertPage,ms_iScrollHorPage,ms_iScrollRightOf,
  1448.                      ms_iScrollBelow,ms_bScrollInvalidate,&ms_xScrolled,&ms_yScrolled);
  1449.         }
  1450. }
  1451.  
  1452.  
  1453.  
  1454. void CSimModelessDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1455. {
  1456.     if(ms_bScrollSupport)
  1457.         {
  1458.         ::BLDScrollDlg((CWnd *)this,WM_HSCROLL,nSBCode,nPos,ms_iScrollVertLine,
  1459.                      ms_iScrollHorLine,ms_iScrollVertPage,ms_iScrollHorPage,ms_iScrollRightOf,
  1460.                      ms_iScrollBelow,ms_bScrollInvalidate,&ms_xScrolled,&ms_yScrolled);
  1461.         }
  1462. }
  1463.  
  1464.  
  1465.  
  1466. void CSimModelessDlg::OnPaint()
  1467. {
  1468.     PAINTSTRUCT ps;
  1469.     HWND hWnd;
  1470.  
  1471.     if(!GetUpdateRect((LPRECT)NULL))
  1472.       return;
  1473.     if(!BeginPaint((LPPAINTSTRUCT)&ps))
  1474.         return;
  1475.  
  1476.     if(ms_szBitmap)
  1477.         ::BLDDrawBkgndBitmap(GetSafeHwnd(),(LPPAINTSTRUCT)&ps,ms_szBitmap,0,ms_bStretch,FALSE,ms_xScrolled,ms_yScrolled);
  1478.  
  1479. // we use 'HWND's to avoid generation of too many temporary CWnds
  1480.     hWnd=::GetWindow(GetSafeHwnd(),GW_CHILD);
  1481.  
  1482.     while(hWnd)
  1483.         {
  1484.         ::SendMessage(hWnd,wPrivateMessage,SIM_CTRLPAINT,
  1485.            (LONG)(LPPAINTSTRUCT)&ps);
  1486.         hWnd=::GetWindow(hWnd,GW_HWNDNEXT);
  1487.         }
  1488.  
  1489.     EndPaint((LPPAINTSTRUCT)&ps);
  1490. }
  1491.  
  1492.  
  1493.  
  1494. HBRUSH CSimModelessDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  1495. {
  1496.  
  1497.     if(nCtlColor == CTLCOLOR_DLG)
  1498.         {
  1499.         if(ms_hBrush)
  1500.             {
  1501.             int x,y,xScrl,yScrl;
  1502. #ifdef WIN32
  1503.             POINT p;
  1504. #else
  1505.             CPoint p;
  1506. #endif
  1507.  
  1508.             if(ms_bScrollSupport)
  1509.                 {
  1510.                 yScrl = ms_yScrolled;
  1511.                 xScrl = ms_xScrolled;
  1512.                 }
  1513.             else
  1514.                 yScrl=yScrl=0;
  1515.             UnrealizeObject(ms_hBrush);
  1516.  
  1517. #ifdef WIN32
  1518.             ::GetBrushOrgEx(pDC->GetSafeHdc(),&p);
  1519.             x=p.x;
  1520.             y=p.y;
  1521. #else
  1522.             p=pDC->GetBrushOrg();
  1523.             x=p.x;
  1524.             y=p.y;
  1525. #endif
  1526.  
  1527.             xScrl=-xScrl+x;
  1528.             yScrl=-yScrl+y;
  1529. #ifdef WIN32
  1530.             ::SetBrushOrgEx(pDC->GetSafeHdc(),xScrl,yScrl,NULL);
  1531. #else
  1532.             pDC->SetBrushOrg(xScrl,yScrl);
  1533. #endif
  1534.             ::SelectObject(pDC->GetSafeHdc(),ms_hBrush);//Assertion failed
  1535.                                                       //when using pDC->SelectObject
  1536.             return ms_hBrush;
  1537.             }
  1538.         }
  1539.     else
  1540.         {
  1541.         HBRUSH hBrushret;
  1542. #ifdef WIN32
  1543.         hBrushret=(HBRUSH)pWnd->SendMessage(wPrivateMessage,SIM_CTLCOLOR,(LPARAM)pDC->m_hDC);
  1544. #else
  1545.         hBrushret=(HBRUSH)LOWORD(pWnd->SendMessage(wPrivateMessage,SIM_CTLCOLOR,MAKELONG(pDC->m_hDC,0)));
  1546. #endif
  1547.         if(hBrushret)
  1548.             return hBrushret;
  1549.         }
  1550.     if(dwDialogProp&BLDGRAY_DIALOGBOX)
  1551.         {
  1552.         switch (nCtlColor)
  1553.             {
  1554.         case CTLCOLOR_LISTBOX:
  1555.         case CTLCOLOR_MSGBOX:
  1556.             {
  1557.             HBRUSH hBrushret;
  1558.             hBrushret=BLDGetGlobalBrushDef(pWnd->GetSafeHwnd(),pDC->GetSafeHdc());
  1559.             if(hBrushret)
  1560.                 return hBrushret;
  1561.             else
  1562.                 return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1563.             }
  1564.             break;
  1565.         case CTLCOLOR_EDIT:
  1566.             if (!(dwDialogProp&BLDGRAY_EDIT))
  1567.                 return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1568.             break;
  1569.         case CTLCOLOR_BTN:
  1570.             if (!(dwDialogProp&BLDGRAY_BUTTON))
  1571.                 return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1572.             break;
  1573.         case CTLCOLOR_SCROLLBAR:
  1574.             if (!(dwDialogProp&BLDGRAY_SCROLLBAR))
  1575.                 return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1576.             break;
  1577.         case CTLCOLOR_STATIC:
  1578.             if (!(dwDialogProp&BLDGRAY_TEXT))
  1579.                 return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1580.              break;
  1581.         case CTLCOLOR_DLG:
  1582.             break;
  1583.         default:
  1584.             return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1585.             break;
  1586.             }
  1587.         pDC->SetBkColor(RGB(192,192,192));
  1588.         return (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  1589.         }
  1590.     return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  1591.     }
  1592.  
  1593.  
  1594.  
  1595. //For default processing of WM_DRAWITEM
  1596. LRESULT CSimModelessDlg::DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
  1597. {
  1598.     if(nMsg == WM_DRAWITEM)
  1599.         {
  1600.         char szStr[20];
  1601.         LPDRAWITEMSTRUCT lpDrawItem = (LPDRAWITEMSTRUCT)lParam;
  1602.         if(lpDrawItem->CtlType == ODT_BUTTON)
  1603.             {
  1604.             ::GetWindowText(lpDrawItem->hwndItem,szStr,20);
  1605.             if(lstrcmpi( (LPSTR)szStr, (LPSTR)"WMP3DBUTTON") == 0 )
  1606.                 {
  1607.                 BLDDrawStateBitmap(lpDrawItem,"","","","",TRUE);
  1608.                 return TRUE;
  1609.                 }
  1610.             }
  1611.         }
  1612.     return CDialog::DefWindowProc(nMsg,wParam,lParam);
  1613. }
  1614.  
  1615.  
  1616.  
  1617. //To support menues in dialogboxes
  1618. BOOL CSimModelessDlg::OnCmdMsg(UINT nID, int nCode, void* pExtra,
  1619.     AFX_CMDHANDLERINFO* pHandlerInfo)
  1620. {
  1621.     //Control command handling ?
  1622.     if (CDialog::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
  1623.         return TRUE;
  1624.  
  1625.     // if not, pump through app
  1626.     CWinApp* pApp = AfxGetApp();
  1627.     if (pApp != NULL &&
  1628.       pApp->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
  1629.         return TRUE;
  1630.  
  1631.     return FALSE;
  1632. }
  1633.  
  1634.  
  1635. //This function is from MFC source for class 'CFrameWnd' to
  1636. //support enabling and disabling of menuitems in dialogboxes
  1637. void CSimModelessDlg::OnInitMenuPopup(CMenu* pMenu, UINT, BOOL bSysMenu)
  1638. {
  1639.  
  1640.     if (bSysMenu)
  1641.         return;     // don't support system menu
  1642.  
  1643.     if(pMenu == NULL)
  1644.         return;
  1645.  
  1646.     // check the enabled state of various menu items
  1647.     CCmdUI state;
  1648.     state.m_pMenu = pMenu;
  1649.  
  1650.     state.m_nIndexMax = pMenu->GetMenuItemCount();
  1651.     for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
  1652.       state.m_nIndex++)
  1653.     {
  1654.         state.m_nID = pMenu->GetMenuItemID(state.m_nIndex);
  1655.         if (state.m_nID == 0)
  1656.             continue; // menu separator or invalid cmd - ignore it
  1657.  
  1658.         if (state.m_nID == (UINT)-1)
  1659.         {
  1660.             // possibly a popup menu, route to first item of that popup
  1661.             state.m_pSubMenu = pMenu->GetSubMenu(state.m_nIndex);
  1662.             if (state.m_pSubMenu == NULL ||
  1663.                 (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
  1664.                 state.m_nID == (UINT)-1)
  1665.             {
  1666.                 continue;       // first item of popup can't be routed to
  1667.             }
  1668.             state.DoUpdate(this, FALSE);    // popups are never auto disabled
  1669.         }
  1670.         else
  1671.         {
  1672.             // normal menu item
  1673.             // Auto enable/disable if frame window has 'm_bAutoMenuEnable'
  1674.             //    set and command is _not_ a system command.
  1675.             state.m_pSubMenu = NULL;
  1676.             state.DoUpdate(this, ms_bAutoMenuEnable && state.m_nID < 0xF000);
  1677.         }
  1678.     }
  1679. }
  1680.  
  1681.  
  1682.  
  1683. LRESULT CSimModelessDlg::OnHelpHitTest(WPARAM wParam, LPARAM lParam)
  1684. {
  1685.     if(ms_HelpID)
  1686.         return ms_HelpID;
  1687.     return CSimModelessDlg::OnHelpHitTest(wParam, lParam);
  1688. }
  1689.  
  1690.  
  1691.  
  1692. IMPLEMENT_DYNCREATE(CSimModelessDlg, CDialog)
  1693.  
  1694. BEGIN_MESSAGE_MAP(CSimModelessDlg, CDialog)
  1695.  
  1696.    ON_WM_CTLCOLOR()
  1697.    ON_WM_PAINT()
  1698.    ON_WM_HSCROLL()
  1699.    ON_WM_VSCROLL()
  1700.    ON_WM_INITMENUPOPUP()
  1701.    ON_MESSAGE(WM_HELPHITTEST, OnHelpHitTest)
  1702.    ON_REGISTERED_MESSAGE(wPrivateMessage,SimHandlePrivateMessage)
  1703.     ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
  1704.     ON_WM_SETCURSOR()
  1705.  
  1706. END_MESSAGE_MAP()
  1707.  
  1708.  
  1709.  
  1710. // *************************************************************
  1711. // Member Functions for Toolbars        : CSimToolbar
  1712. // Base Class                           : CDialogBar
  1713. // *************************************************************
  1714.  
  1715. CSimToolbar::CSimToolbar()
  1716.       : CDialogBar()
  1717. {
  1718.     ms_bDeleteBrush=ms_bScrollSupport=FALSE;
  1719.     ms_hBrush=0;
  1720.     ms_szBitmap=NULL;
  1721.     ms_nThisStyle=0;
  1722. }
  1723.  
  1724.  
  1725.  
  1726. CSimToolbar::~CSimToolbar()
  1727. {
  1728.     if(ms_bDeleteBrush && ms_hBrush)
  1729.         DeleteObject(ms_hBrush);
  1730.     ms_bDeleteBrush=FALSE;
  1731.     ms_hBrush=0;
  1732.     if(ms_szBitmap)
  1733.         delete ms_szBitmap;
  1734. }
  1735.  
  1736.  
  1737.  
  1738. void CSimToolbar::OnNcDestroy()
  1739. {
  1740.     CWnd* pParentWnd = GetParent();
  1741.     BLDSetChildDialog SetChildDialog;
  1742.     SetChildDialog.pWnd  =0;
  1743.     SetChildDialog.nStyle=ms_nThisStyle;
  1744.     if(pParentWnd)
  1745.         pParentWnd->SendMessage(wPrivateMessage,SIM_SETCHILDDIALOG,(LONG)(LPBLDSetChildDialog)&SetChildDialog);
  1746.     CDialogBar::OnNcDestroy();
  1747. }
  1748.  
  1749.  
  1750.  
  1751.  
  1752.  
  1753. int CSimToolbar::OnCreate(LPCREATESTRUCT lpcs)
  1754. {
  1755.     //OnCreate is declared in MFC's class CControlBar but not implemented.
  1756.     //This functions is added here to avoid link error if
  1757.     //WM_CREATE message is processed
  1758.     return 0;
  1759. }
  1760.  
  1761.  
  1762. //Prepares dialog template resource before calling
  1763. //CDialogBar::Create().
  1764. //This function removes unwanted styles in the template before it calls
  1765. //CDialogBar::Create which will fail if the style includes WS_VISIBLE
  1766. //and not includes WS_CHILD
  1767.  
  1768. BOOL CSimToolbar::Create(CWnd* pParentWnd, LPCSTR lpszTemplateName,
  1769.            UINT nStyle, UINT nID)
  1770. {
  1771.     CSize m_sizeFixedLayoutOld; //Size of old toolbar if any
  1772.  
  1773.     //Find parent of type CFrameWnd or derived class.
  1774.     if(!pParentWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)))
  1775.         {
  1776.         pParentWnd = pParentWnd->GetParent();
  1777.         while (pParentWnd != NULL)
  1778.             {
  1779.             if (pParentWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)))
  1780.                 break;
  1781.             pParentWnd = pParentWnd->GetParent();
  1782.             }
  1783.         }
  1784.     if(!pParentWnd)
  1785.         {
  1786.         return FALSE;
  1787.         }
  1788. //Remove old toolbar with same style if any
  1789.     CSimToolbar* pOld=(CSimToolbar*)pParentWnd->SendMessage(wPrivateMessage,SIM_GETCHILDDIALOG,MAKELONG(nStyle,0));
  1790.     if(pOld)
  1791.          {
  1792.          m_sizeFixedLayoutOld = pOld->m_sizeFixedLayout;
  1793.          pOld->DestroyWindow();
  1794.          }
  1795.     else
  1796.         m_sizeFixedLayoutOld.cx=m_sizeFixedLayoutOld.cy=0;
  1797.  
  1798.     m_bAutoDelete=TRUE;  //Delete CSimToolbar object when window is destroyed
  1799.  
  1800.     HRSRC hResource = ::FindResource(AfxGetResourceHandle(), lpszTemplateName, RT_DIALOG);
  1801.     if (hResource == NULL)
  1802.         {
  1803.         return FALSE;
  1804.         }
  1805.  
  1806.     HGLOBAL hTemplate = ::LoadResource(AfxGetResourceHandle(), hResource);
  1807.     if (hTemplate == NULL)
  1808.         {
  1809.         return FALSE;
  1810.         }
  1811.     // style is first DWORD in resource
  1812.     void FAR * lpResource =::LockResource(hTemplate);
  1813.  
  1814.     DWORD dwOldStyle = *(DWORD FAR*)lpResource;
  1815.  
  1816.     DWORD tmpdwStyle = dwOldStyle&(TOOLBARSTRIP);
  1817.     DWORD dwStyle    = dwOldStyle^tmpdwStyle;
  1818.     dwStyle          = dwStyle | WS_CHILD | WS_CLIPSIBLINGS;
  1819.  
  1820.     *(DWORD FAR*)lpResource= dwStyle; //Set new style dialog template
  1821.     BOOL retval = CDialogBar::Create(pParentWnd,lpszTemplateName,nStyle,nID);
  1822.  
  1823.     *(DWORD FAR*)lpResource= dwOldStyle; //Reset style
  1824.  
  1825. #ifdef WIN32
  1826.     // It is not necessary for Win32 applications to unlock resources.
  1827. #else
  1828.     ::UnlockResource(hTemplate);
  1829. #endif
  1830.  
  1831.     ::FreeResource(hTemplate);
  1832.  
  1833.     if(retval)          //There is no OnInitDialog() in base MFC class CDialogBar
  1834.         OnInitDialog(); //so we have to invoke it directly
  1835.  
  1836.     ms_nThisStyle = nStyle;
  1837.  
  1838.     //Make parent aware of this child window
  1839.     BLDSetChildDialog SetChildDialog;
  1840.     SetChildDialog.pWnd  =this;
  1841.     SetChildDialog.nStyle=ms_nThisStyle;
  1842.     pParentWnd->SendMessage(wPrivateMessage,SIM_SETCHILDDIALOG,(LONG)(LPBLDSetChildDialog)&SetChildDialog);
  1843.  
  1844.     CSimClientDlg* pClient=(CSimClientDlg*)pParentWnd->SendMessage(wPrivateMessage,SIM_GETCHILDDIALOG,0);
  1845.     if(pClient)
  1846.        {//Need to resize parent if there are client area controls
  1847.        CRect rectParent;
  1848.        pParentWnd->GetWindowRect(rectParent);
  1849.        CSize size = rectParent.Size();
  1850.        CRect rectToolbar;
  1851.        GetWindowRect(rectToolbar);
  1852.        switch(nStyle)
  1853.            {
  1854.        case CBRS_RIGHT:
  1855.        case CBRS_LEFT:
  1856.            //Increase the with of the parenwindow
  1857.            size.cx +=m_sizeFixedLayout.cx-m_sizeFixedLayoutOld.cx;
  1858.            break;
  1859.        case CBRS_BOTTOM:
  1860.        case CBRS_TOP:
  1861.            //Increase the height of the parenwindow
  1862.            size.cy +=m_sizeFixedLayout.cy-m_sizeFixedLayoutOld.cy;
  1863.            break;
  1864.            }
  1865.        pParentWnd->SetWindowPos(NULL, 0, 0, size.cx, size.cy,
  1866.            SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
  1867.        }
  1868.     pParentWnd->RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST);
  1869.     return retval;
  1870. }
  1871.  
  1872.  
  1873.  
  1874. BOOL CSimToolbar::OnInitDialog()
  1875. {
  1876.     return TRUE;
  1877. }
  1878.  
  1879.  
  1880.  
  1881. void CSimToolbar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
  1882. {
  1883.  //Overrides the call to this function and set the
  1884.  //'bDisableIfNoHndler' to FALSE so Pushbuttons not are disabled
  1885.  //See  BARDLG.CPP and BARCORE.CPP on the MFC source directory
  1886.  
  1887.     CDialogBar::OnUpdateCmdUI(pTarget,FALSE);
  1888. }
  1889.  
  1890.  
  1891.  
  1892. LRESULT CSimToolbar::WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
  1893. {
  1894.  //In CControlBar (which is the base of CDialogBar) WM_COMMAND,WM_DRAWITEM,
  1895.  //WM_MEASUREITEM,WM_DELETEITEM,WM_COMPAREITEM,WM_VKEYTOITEM,
  1896.  //WM_CHARTOITEM and WM_VBXEVENT are directly
  1897.  //sent to the parent window, see CControlBar::WindowProc in BARCORE.CPP. on
  1898.  //the MFC source directory.
  1899.  //
  1900.  //We want that all messages are handled as in dialog boxes so messages
  1901.  //are passed directly to the base of CControlBar, CWnd.
  1902.  
  1903.     return CWnd::WindowProc(nMsg,wParam,lParam);
  1904. }
  1905.  
  1906.  
  1907.  
  1908. LRESULT CSimToolbar::SimHandlePrivateMessage(WPARAM wParam,LPARAM lParam)
  1909. {
  1910.     CSize m_sizeFixedLayoutOld; //Old size of toolbar
  1911.  
  1912.     int        Cx,Cy;
  1913.     RECT       Rect;
  1914.  
  1915.     if(wParam != SIM_SIZEDIALOG)
  1916.         return FALSE;
  1917.  
  1918.     BLDFindCtrlsRightBottom(this,&Cx,&Cy);
  1919.  
  1920.     Cx += LOWORD(lParam);
  1921.     Cy += HIWORD(lParam);
  1922.  
  1923.     GetClientRect((LPRECT)&Rect);
  1924.     if (Rect.right >= Cx && Rect.bottom >= Cy )
  1925.         return TRUE;
  1926.  
  1927.     m_sizeFixedLayoutOld = m_sizeFixedLayout;
  1928.  
  1929.     if(Rect.right < Cx)
  1930.         {
  1931.         switch(ms_nThisStyle)
  1932.             {
  1933.         case CBRS_RIGHT:
  1934.         case CBRS_LEFT:
  1935.             m_sizeFixedLayout.cx += Cx - Rect.right;
  1936.             break;
  1937.             }
  1938.         }
  1939.  
  1940.     if(Rect.bottom < Cy)
  1941.         {
  1942.         switch(ms_nThisStyle)
  1943.             {
  1944.         case CBRS_BOTTOM:
  1945.         case CBRS_TOP:
  1946.             m_sizeFixedLayout.cy += Cy - Rect.bottom;
  1947.             break;
  1948.             }
  1949.         }
  1950.     CSimClientDlg* pClient=(CSimClientDlg*)GetParent()->SendMessage(wPrivateMessage,SIM_GETCHILDDIALOG,0);
  1951.     if(pClient)
  1952.        {//Need to resize parent if there are client area controls
  1953.        CRect rectParent;
  1954.        GetParent()->GetWindowRect(rectParent);
  1955.        CSize size = rectParent.Size();
  1956.        CRect rectToolbar;
  1957.        GetWindowRect(rectToolbar);
  1958.        switch(ms_nThisStyle)
  1959.            {
  1960.        case CBRS_RIGHT:
  1961.        case CBRS_LEFT:
  1962.            //Increase the with of the parenwindow
  1963.            size.cx +=m_sizeFixedLayout.cx-m_sizeFixedLayoutOld.cx;
  1964.            break;
  1965.        case CBRS_BOTTOM:
  1966.        case CBRS_TOP:
  1967.            //Increase the height of the parenwindow
  1968.            size.cy +=m_sizeFixedLayout.cy-m_sizeFixedLayoutOld.cy;
  1969.            break;
  1970.            }
  1971.        GetParent()->SetWindowPos(NULL, 0, 0, size.cx, size.cy,
  1972.            SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
  1973.        }
  1974.  
  1975.     GetParent()->RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST);
  1976.     return TRUE;
  1977. }
  1978.  
  1979.  
  1980.  
  1981. void CSimToolbar::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1982. {
  1983.     if(ms_bScrollSupport)
  1984.         {
  1985.         ::BLDScrollDlg((CWnd *)this,WM_VSCROLL,nSBCode,nPos,ms_iScrollVertLine,
  1986.                      ms_iScrollHorLine,ms_iScrollVertPage,ms_iScrollHorPage,ms_iScrollRightOf,
  1987.                      ms_iScrollBelow,ms_bScrollInvalidate,&ms_xScrolled,&ms_yScrolled);
  1988.         }
  1989. }
  1990.  
  1991.  
  1992.  
  1993. void CSimToolbar::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1994. {
  1995.     if(ms_bScrollSupport)
  1996.         {
  1997.         ::BLDScrollDlg((CWnd *)this,WM_HSCROLL,nSBCode,nPos,ms_iScrollVertLine,
  1998.                      ms_iScrollHorLine,ms_iScrollVertPage,ms_iScrollHorPage,ms_iScrollRightOf,
  1999.                      ms_iScrollBelow,ms_bScrollInvalidate,&ms_xScrolled,&ms_yScrolled);
  2000.         }
  2001. }
  2002.  
  2003.  
  2004.  
  2005. void CSimToolbar::OnPaint()
  2006. {
  2007.     PAINTSTRUCT ps;
  2008.     HWND hWnd;
  2009.  
  2010.     if(!GetUpdateRect((LPRECT)NULL))
  2011.       return;
  2012.     if(!BeginPaint((LPPAINTSTRUCT)&ps))
  2013.         return;
  2014.  
  2015.     if(ms_szBitmap)
  2016.         ::BLDDrawBkgndBitmap(GetSafeHwnd(),(LPPAINTSTRUCT)&ps,ms_szBitmap,0,ms_bStretch,FALSE,ms_xScrolled,ms_yScrolled);
  2017.  
  2018. // we use 'HWND's to avoid generation of too many temporary CWnds
  2019.     hWnd=::GetWindow(GetSafeHwnd(),GW_CHILD);
  2020.  
  2021.     while(hWnd)
  2022.         {
  2023.         ::SendMessage(hWnd,wPrivateMessage,SIM_CTRLPAINT,
  2024.            (LONG)(LPPAINTSTRUCT)&ps);
  2025.         hWnd=::GetWindow(hWnd,GW_HWNDNEXT);
  2026.         }
  2027.  
  2028.     EndPaint((LPPAINTSTRUCT)&ps);
  2029. }
  2030.  
  2031.  
  2032.  
  2033. HBRUSH CSimToolbar::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  2034. {
  2035.  
  2036.     if(nCtlColor == CTLCOLOR_DLG)
  2037.         {
  2038.         if(ms_hBrush)
  2039.             {
  2040.             int x,y,xScrl,yScrl;
  2041. #ifdef WIN32
  2042.             POINT p;
  2043. #else
  2044.             CPoint p;
  2045. #endif
  2046.  
  2047.             if(ms_bScrollSupport)
  2048.                 {
  2049.                 yScrl = ms_yScrolled;
  2050.                 xScrl = ms_xScrolled;
  2051.                 }
  2052.             else
  2053.                 yScrl=yScrl=0;
  2054.             UnrealizeObject(ms_hBrush);
  2055.  
  2056. #ifdef WIN32
  2057.             ::GetBrushOrgEx(pDC->GetSafeHdc(),&p);
  2058.             x=p.x;
  2059.             y=p.y;
  2060. #else
  2061.             p=pDC->GetBrushOrg();
  2062.             x=p.x;
  2063.             y=p.y;
  2064. #endif
  2065.  
  2066.             xScrl=-xScrl+x;
  2067.             yScrl=-yScrl+y;
  2068. #ifdef WIN32
  2069.             ::SetBrushOrgEx(pDC->GetSafeHdc(),xScrl,yScrl,NULL);
  2070. #else
  2071.             pDC->SetBrushOrg(xScrl,yScrl);
  2072. #endif
  2073.             ::SelectObject(pDC->GetSafeHdc(),ms_hBrush);//Assertion failed
  2074.                                                       //when using pDC->SelectObject
  2075.             return ms_hBrush;
  2076.             }
  2077.         }
  2078.     else
  2079.         {
  2080.         HBRUSH hBrushret;
  2081. #ifdef WIN32
  2082.         hBrushret=(HBRUSH)pWnd->SendMessage(wPrivateMessage,SIM_CTLCOLOR,(LPARAM)pDC->m_hDC);
  2083. #else
  2084.         hBrushret=(HBRUSH)LOWORD(pWnd->SendMessage(wPrivateMessage,SIM_CTLCOLOR,MAKELONG(pDC->m_hDC,0)));
  2085. #endif
  2086.         if(hBrushret)
  2087.             return hBrushret;
  2088.         }
  2089.     if(dwDialogProp&BLDGRAY_DIALOGBOX)
  2090.         {
  2091.         switch (nCtlColor)
  2092.             {
  2093.         case CTLCOLOR_LISTBOX:
  2094.         case CTLCOLOR_MSGBOX:
  2095.             {
  2096.             HBRUSH hBrushret;
  2097.             hBrushret=BLDGetGlobalBrushDef(pWnd->GetSafeHwnd(),pDC->GetSafeHdc());
  2098.             if(hBrushret)
  2099.                 return hBrushret;
  2100.             else
  2101.                 return CDialogBar::OnCtlColor(pDC,pWnd,nCtlColor);
  2102.             }
  2103.             break;
  2104.         case CTLCOLOR_EDIT:
  2105.             if (!(dwDialogProp&BLDGRAY_EDIT))
  2106.                 return CDialogBar::OnCtlColor(pDC,pWnd,nCtlColor);
  2107.             break;
  2108.         case CTLCOLOR_BTN:
  2109.             if (!(dwDialogProp&BLDGRAY_BUTTON))
  2110.                 return CDialogBar::OnCtlColor(pDC,pWnd,nCtlColor);
  2111.             break;
  2112.         case CTLCOLOR_SCROLLBAR:
  2113.             if (!(dwDialogProp&BLDGRAY_SCROLLBAR))
  2114.                 return CDialogBar::OnCtlColor(pDC,pWnd,nCtlColor);
  2115.             break;
  2116.         case CTLCOLOR_STATIC:
  2117.             if (!(dwDialogProp&BLDGRAY_TEXT))
  2118.                 return CDialogBar::OnCtlColor(pDC,pWnd,nCtlColor);
  2119.              break;
  2120.         case CTLCOLOR_DLG:
  2121.             break;
  2122.         default:
  2123.             return CDialogBar::OnCtlColor(pDC,pWnd,nCtlColor);
  2124.             break;
  2125.             }
  2126.         pDC->SetBkColor(RGB(192,192,192));
  2127.         return (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  2128.         }
  2129.     return CDialogBar::OnCtlColor(pDC,pWnd,nCtlColor);
  2130.     }
  2131.  
  2132.  
  2133.  
  2134. //For default processing of WM_DRAWITEM
  2135. LRESULT CSimToolbar::DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
  2136. {
  2137.     if(nMsg == WM_DRAWITEM)
  2138.         {
  2139.         char szStr[20];
  2140.         LPDRAWITEMSTRUCT lpDrawItem = (LPDRAWITEMSTRUCT)lParam;
  2141.         if(lpDrawItem->CtlType == ODT_BUTTON)
  2142.             {
  2143.             ::GetWindowText(lpDrawItem->hwndItem,szStr,20);
  2144.             if(lstrcmpi( (LPSTR)szStr, (LPSTR)"WMP3DBUTTON") == 0 )
  2145.                 {
  2146.                 BLDDrawStateBitmap(lpDrawItem,"","","","",TRUE);
  2147.                 return TRUE;
  2148.                 }
  2149.             }
  2150.         }
  2151.     return CDialogBar::DefWindowProc(nMsg,wParam,lParam);
  2152. }
  2153.  
  2154.  
  2155.  
  2156. //To support menues in dialogboxes
  2157. BOOL CSimToolbar::OnCmdMsg(UINT nID, int nCode, void* pExtra,
  2158.     AFX_CMDHANDLERINFO* pHandlerInfo)
  2159. {
  2160.     //Control command handling ?
  2161.     if (CDialogBar::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
  2162.         return TRUE;
  2163.  
  2164.     // if not, pump through app
  2165.     CWinApp* pApp = AfxGetApp();
  2166.     if (pApp != NULL &&
  2167.       pApp->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
  2168.         return TRUE;
  2169.  
  2170.     return FALSE;
  2171. }
  2172.  
  2173.  
  2174. //This function is from MFC source for class 'CFrameWnd' to
  2175. //support enabling and disabling of menuitems in dialogboxes
  2176. void CSimToolbar::OnInitMenuPopup(CMenu* pMenu, UINT, BOOL bSysMenu)
  2177. {
  2178.  
  2179.     if (bSysMenu)
  2180.         return;     // don't support system menu
  2181.  
  2182.     if(pMenu == NULL)
  2183.         return;
  2184.  
  2185.     // check the enabled state of various menu items
  2186.     CCmdUI state;
  2187.     state.m_pMenu = pMenu;
  2188.  
  2189.     state.m_nIndexMax = pMenu->GetMenuItemCount();
  2190.     for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
  2191.       state.m_nIndex++)
  2192.     {
  2193.         state.m_nID = pMenu->GetMenuItemID(state.m_nIndex);
  2194.         if (state.m_nID == 0)
  2195.             continue; // menu separator or invalid cmd - ignore it
  2196.  
  2197.         if (state.m_nID == (UINT)-1)
  2198.         {
  2199.             // possibly a popup menu, route to first item of that popup
  2200.             state.m_pSubMenu = pMenu->GetSubMenu(state.m_nIndex);
  2201.             if (state.m_pSubMenu == NULL ||
  2202.                 (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
  2203.                 state.m_nID == (UINT)-1)
  2204.             {
  2205.                 continue;       // first item of popup can't be routed to
  2206.             }
  2207.             state.DoUpdate(this, FALSE);    // popups are never auto disabled
  2208.         }
  2209.         else
  2210.         {
  2211.             // normal menu item
  2212.             // Auto enable/disable if frame window has 'm_bAutoMenuEnable'
  2213.             //    set and command is _not_ a system command.
  2214.             state.m_pSubMenu = NULL;
  2215.             state.DoUpdate(this, ms_bAutoMenuEnable && state.m_nID < 0xF000);
  2216.         }
  2217.     }
  2218. }
  2219.  
  2220.  
  2221.  
  2222. LRESULT CSimToolbar::OnHelpHitTest(WPARAM wParam, LPARAM lParam)
  2223. {
  2224.     if(ms_HelpID)
  2225.         return ms_HelpID;
  2226.     return CSimToolbar::OnHelpHitTest(wParam, lParam);
  2227. }
  2228.  
  2229.  
  2230.  
  2231. IMPLEMENT_DYNCREATE(CSimToolbar, CDialogBar)
  2232.  
  2233. BEGIN_MESSAGE_MAP(CSimToolbar, CDialogBar)
  2234.  
  2235.    ON_WM_CTLCOLOR()
  2236.    ON_WM_PAINT()
  2237.    ON_WM_HSCROLL()
  2238.    ON_WM_VSCROLL()
  2239.    ON_WM_INITMENUPOPUP()
  2240.    ON_MESSAGE(WM_HELPHITTEST, OnHelpHitTest)
  2241.    ON_REGISTERED_MESSAGE(wPrivateMessage,SimHandlePrivateMessage)
  2242.    ON_WM_NCDESTROY()
  2243.  
  2244. END_MESSAGE_MAP()
  2245.  
  2246.  
  2247.  
  2248. // *************************************************************
  2249. // Member Functions client area controls : CSimClientDlg
  2250. // Base Class                            : CFormView
  2251. // *************************************************************
  2252.  
  2253. CSimClientDlg::CSimClientDlg(LPCSTR lpszTemplateName)
  2254.       : CFormView(lpszTemplateName)
  2255. {
  2256.     ms_bDeleteBrush=ms_bScrollSupport=FALSE;
  2257.     ms_hBrush=0;
  2258.     ms_szBitmap=NULL;
  2259.     m_bInsideUpdate=TRUE; //This member data is used in MFC
  2260.                           //CScrollView::UpdateBars to avoid recursiv
  2261.                           //calls into the function.
  2262.                           //CScrollView::UpdateBars sets ore removes
  2263.                           //scrolbars depending in the size of the view.
  2264.                           //m_bInsideUpdate is set to TRUE here so the
  2265.                           //function is never executed.
  2266. }
  2267.  
  2268.  
  2269.  
  2270. CSimClientDlg::CSimClientDlg()
  2271.       : CFormView((LPCSTR)NULL)
  2272. {
  2273.     ms_bDeleteBrush=ms_bScrollSupport=FALSE;
  2274.     ms_hBrush=0;
  2275.     ms_szBitmap=NULL;
  2276.  
  2277. }
  2278.  
  2279.  
  2280.  
  2281. void CSimClientDlg::SimSetTemplate(LPCSTR lpszTemplateName)
  2282. {
  2283.     m_lpszTemplateName = lpszTemplateName;
  2284. }
  2285.  
  2286.  
  2287.  
  2288. CSimClientDlg::~CSimClientDlg()
  2289. {
  2290.     if(ms_bDeleteBrush && ms_hBrush)
  2291.         DeleteObject(ms_hBrush);
  2292.     ms_bDeleteBrush=FALSE;
  2293.     ms_hBrush=0;
  2294.     if(ms_szBitmap)
  2295.         delete ms_szBitmap;
  2296. }
  2297.  
  2298.  
  2299.  
  2300. void CSimClientDlg::OnNcDestroy()
  2301. {
  2302.     CWnd* pParentWnd = GetParent();
  2303.     BLDSetChildDialog SetChildDialog;
  2304.     SetChildDialog.pWnd  =NULL;
  2305.     SetChildDialog.nStyle=0;
  2306.     if(pParentWnd)
  2307.         pParentWnd->SendMessage(wPrivateMessage,SIM_SETCHILDDIALOG,(LONG)(LPBLDSetChildDialog)&SetChildDialog);
  2308.     CFormView::OnNcDestroy();
  2309. }
  2310.  
  2311.  
  2312. //Prepares dialog template resource before calling
  2313. //CFormView::Create().
  2314. //This function removes unwanted styles in the template before it calls
  2315. //CFormView::Create which will fail if the style includes WS_VISIBLE
  2316. //and not includes WS_CHILD
  2317.  
  2318. BOOL CSimClientDlg::Create(CWnd *pParentWnd)
  2319. {
  2320.     //Find parent of type CFrameWnd or derived class.
  2321.     if(!pParentWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)))
  2322.         {
  2323.         pParentWnd = pParentWnd->GetParent();
  2324.         while (pParentWnd != NULL)
  2325.             {
  2326.             if (pParentWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)))
  2327.                 break;
  2328.             pParentWnd = pParentWnd->GetParent();
  2329.             }
  2330.         }
  2331.     if(!pParentWnd)
  2332.         {
  2333.         return FALSE;
  2334.         }
  2335. //Remove old client area controls if any
  2336.     CSimClientDlg* pOld=(CSimClientDlg*)pParentWnd->SendMessage(wPrivateMessage,SIM_GETCHILDDIALOG,0);
  2337.     if(pOld)
  2338.          pOld->DestroyWindow();
  2339.  
  2340.     HRSRC hResource = ::FindResource(AfxGetResourceHandle(), m_lpszTemplateName, RT_DIALOG);
  2341.     if (hResource == NULL)
  2342.         {
  2343.         return FALSE;
  2344.         }
  2345.  
  2346.     HGLOBAL hTemplate = ::LoadResource(AfxGetResourceHandle(), hResource);
  2347.     if (hTemplate == NULL)
  2348.         {
  2349.         return FALSE;
  2350.         }
  2351.     // style is first DWORD in resource
  2352.     void FAR * lpResource =::LockResource(hTemplate);
  2353.  
  2354.     DWORD dwOldStyle = *(DWORD FAR*)lpResource;
  2355.  
  2356.     DWORD tmpdwStyle = dwOldStyle&(CLIENTSTRIP);
  2357.     DWORD dwStyle    = dwOldStyle^tmpdwStyle;
  2358.     dwStyle          = dwStyle | WS_CHILD | WS_CLIPSIBLINGS;
  2359.  
  2360.     *(DWORD FAR*)lpResource= dwStyle; //Set new style dialog template
  2361.     CCreateContext CContext;
  2362.     //MFC needs a pointer to a CCreateContext
  2363.     CContext.m_pNewViewClass  =NULL;
  2364.     CContext.m_pCurrentDoc    =NULL;
  2365.     CContext.m_pNewDocTemplate=NULL;
  2366.     CContext.m_pLastView      =NULL;
  2367.     CContext.m_pCurrentFrame  =NULL;
  2368.     BOOL retval = CFormView::Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
  2369.                 CRect(0,0,0,0), pParentWnd, AFX_IDW_PANE_FIRST, &CContext);
  2370.  
  2371.  
  2372.     *(DWORD FAR*)lpResource= dwOldStyle; //Reset style
  2373.  
  2374. #ifdef WIN32
  2375.     // It is not necessary for Win32 applications to unlock resources.
  2376. #else
  2377.     ::UnlockResource(hTemplate);
  2378. #endif
  2379.  
  2380.     ::FreeResource(hTemplate);
  2381.  
  2382.     if(retval)          //There is no OnInitDialog() in base MFC class CFormView
  2383.         OnInitDialog(); //so we have to invoke it directly
  2384.  
  2385.     //Make parent aware of this child window
  2386.     BLDSetChildDialog SetChildDialog;
  2387.     SetChildDialog.pWnd  =this;
  2388.     SetChildDialog.nStyle=0;
  2389.     pParentWnd->SendMessage(wPrivateMessage,SIM_SETCHILDDIALOG,(LONG)(LPBLDSetChildDialog)&SetChildDialog);
  2390.  
  2391.     //MFC FormView assumes that scrollbars not are a part of the
  2392.     //template so height/width for scrollbars are added if any
  2393.     //Remove this extra height/width.
  2394.     if(dwOldStyle & WS_HSCROLL)
  2395.         m_totalDev.cy-=GetSystemMetrics(SM_CYHSCROLL);
  2396.     if(dwOldStyle & WS_VSCROLL)
  2397.         m_totalDev.cx-=GetSystemMetrics(SM_CXVSCROLL);
  2398.     pParentWnd->RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST);
  2399.     ResizeParentToFit(FALSE);
  2400.     return retval;
  2401. }
  2402.  
  2403.  
  2404.  
  2405. BOOL CSimClientDlg::OnInitDialog()
  2406. {
  2407.     return TRUE;
  2408. }
  2409.  
  2410.  
  2411.  
  2412. LRESULT CSimClientDlg::SimHandlePrivateMessage(WPARAM wParam,LPARAM lParam)
  2413. {
  2414.     int Cx,Cy;
  2415.     RECT        Rect;
  2416.  
  2417.     if(wParam != SIM_SIZEDIALOG)
  2418.         return FALSE;
  2419.  
  2420.     BLDFindCtrlsRightBottom(this,&Cx,&Cy);
  2421.  
  2422.     Cx += LOWORD(lParam);
  2423.     Cy += HIWORD(lParam);
  2424.  
  2425.     GetClientRect((LPRECT)&Rect);
  2426.     if (Rect.right >= Cx && Rect.bottom >= Cy )
  2427.         return TRUE;
  2428.  
  2429.     if(Rect.right < Cx)
  2430.         m_totalDev.cx += Cx - Rect.right;
  2431.  
  2432.     if(Rect.bottom < Cy)
  2433.         m_totalDev.cy += Cy - Rect.bottom;
  2434.  
  2435.     GetParent()->RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST);
  2436.     ResizeParentToFit(FALSE);
  2437.     return TRUE;
  2438. }
  2439.  
  2440.  
  2441.  
  2442. void CSimClientDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  2443. {
  2444.     if(ms_bScrollSupport)
  2445.         {
  2446.         ::BLDScrollDlg((CWnd *)this,WM_VSCROLL,nSBCode,nPos,ms_iScrollVertLine,
  2447.                      ms_iScrollHorLine,ms_iScrollVertPage,ms_iScrollHorPage,ms_iScrollRightOf,
  2448.                      ms_iScrollBelow,ms_bScrollInvalidate,&ms_xScrolled,&ms_yScrolled);
  2449.         }
  2450. }
  2451.  
  2452.  
  2453.  
  2454. void CSimClientDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  2455. {
  2456.     if(ms_bScrollSupport)
  2457.         {
  2458.         ::BLDScrollDlg((CWnd *)this,WM_HSCROLL,nSBCode,nPos,ms_iScrollVertLine,
  2459.                      ms_iScrollHorLine,ms_iScrollVertPage,ms_iScrollHorPage,ms_iScrollRightOf,
  2460.                      ms_iScrollBelow,ms_bScrollInvalidate,&ms_xScrolled,&ms_yScrolled);
  2461.         }
  2462. }
  2463.  
  2464.  
  2465.  
  2466. void CSimClientDlg::OnPaint()
  2467. {
  2468.     PAINTSTRUCT ps;
  2469.     HWND hWnd;
  2470.  
  2471.     if(!GetUpdateRect((LPRECT)NULL))
  2472.       return;
  2473.     if(!BeginPaint((LPPAINTSTRUCT)&ps))
  2474.         return;
  2475.  
  2476.     if(ms_szBitmap)
  2477.         ::BLDDrawBkgndBitmap(GetSafeHwnd(),(LPPAINTSTRUCT)&ps,ms_szBitmap,0,ms_bStretch,FALSE,ms_xScrolled,ms_yScrolled);
  2478.  
  2479. // we use 'HWND's to avoid generation of too many temporary CWnds
  2480.     hWnd=::GetWindow(GetSafeHwnd(),GW_CHILD);
  2481.  
  2482.     while(hWnd)
  2483.         {
  2484.         ::SendMessage(hWnd,wPrivateMessage,SIM_CTRLPAINT,
  2485.            (LONG)(LPPAINTSTRUCT)&ps);
  2486.         hWnd=::GetWindow(hWnd,GW_HWNDNEXT);
  2487.         }
  2488.  
  2489.     EndPaint((LPPAINTSTRUCT)&ps);
  2490. }
  2491.  
  2492.  
  2493.  
  2494. HBRUSH CSimClientDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  2495. {
  2496.  
  2497.     if(nCtlColor == CTLCOLOR_DLG)
  2498.         {
  2499.         if(ms_hBrush)
  2500.             {
  2501.             int x,y,xScrl,yScrl;
  2502. #ifdef WIN32
  2503.             POINT p;
  2504. #else
  2505.             CPoint p;
  2506. #endif
  2507.  
  2508.             if(ms_bScrollSupport)
  2509.                 {
  2510.                 yScrl = ms_yScrolled;
  2511.                 xScrl = ms_xScrolled;
  2512.                 }
  2513.             else
  2514.                 yScrl=yScrl=0;
  2515.             UnrealizeObject(ms_hBrush);
  2516.  
  2517. #ifdef WIN32
  2518.             ::GetBrushOrgEx(pDC->GetSafeHdc(),&p);
  2519.             x=p.x;
  2520.             y=p.y;
  2521. #else
  2522.             p=pDC->GetBrushOrg();
  2523.             x=p.x;
  2524.             y=p.y;
  2525. #endif
  2526.  
  2527.             xScrl=-xScrl+x;
  2528.             yScrl=-yScrl+y;
  2529. #ifdef WIN32
  2530.             ::SetBrushOrgEx(pDC->GetSafeHdc(),xScrl,yScrl,NULL);
  2531. #else
  2532.             pDC->SetBrushOrg(xScrl,yScrl);
  2533. #endif
  2534.             ::SelectObject(pDC->GetSafeHdc(),ms_hBrush);//Assertion failed
  2535.                                                       //when using pDC->SelectObject
  2536.             return ms_hBrush;
  2537.             }
  2538.         }
  2539.     else
  2540.         {
  2541.         HBRUSH hBrushret;
  2542. #ifdef WIN32
  2543.         hBrushret=(HBRUSH)pWnd->SendMessage(wPrivateMessage,SIM_CTLCOLOR,(LPARAM)pDC->m_hDC);
  2544. #else
  2545.         hBrushret=(HBRUSH)LOWORD(pWnd->SendMessage(wPrivateMessage,SIM_CTLCOLOR,MAKELONG(pDC->m_hDC,0)));
  2546. #endif
  2547.         if(hBrushret)
  2548.             return hBrushret;
  2549.         }
  2550.     if(dwDialogProp&BLDGRAY_DIALOGBOX)
  2551.         {
  2552.         switch (nCtlColor)
  2553.             {
  2554.         case CTLCOLOR_LISTBOX:
  2555.         case CTLCOLOR_MSGBOX:
  2556.             {
  2557.             HBRUSH hBrushret;
  2558.             hBrushret=BLDGetGlobalBrushDef(pWnd->GetSafeHwnd(),pDC->GetSafeHdc());
  2559.             if(hBrushret)
  2560.                 return hBrushret;
  2561.             else
  2562.                 return CFormView::OnCtlColor(pDC,pWnd,nCtlColor);
  2563.             }
  2564.             break;
  2565.         case CTLCOLOR_EDIT:
  2566.             if (!(dwDialogProp&BLDGRAY_EDIT))
  2567.                 return CFormView::OnCtlColor(pDC,pWnd,nCtlColor);
  2568.             break;
  2569.         case CTLCOLOR_BTN:
  2570.             if (!(dwDialogProp&BLDGRAY_BUTTON))
  2571.                 return CFormView::OnCtlColor(pDC,pWnd,nCtlColor);
  2572.             break;
  2573.         case CTLCOLOR_SCROLLBAR:
  2574.             if (!(dwDialogProp&BLDGRAY_SCROLLBAR))
  2575.                 return CFormView::OnCtlColor(pDC,pWnd,nCtlColor);
  2576.             break;
  2577.         case CTLCOLOR_STATIC:
  2578.             if (!(dwDialogProp&BLDGRAY_TEXT))
  2579.                 return CFormView::OnCtlColor(pDC,pWnd,nCtlColor);
  2580.              break;
  2581.         case CTLCOLOR_DLG:
  2582.             break;
  2583.         default:
  2584.             return CFormView::OnCtlColor(pDC,pWnd,nCtlColor);
  2585.             break;
  2586.             }
  2587.         pDC->SetBkColor(RGB(192,192,192));
  2588.         return (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  2589.         }
  2590.     return CFormView::OnCtlColor(pDC,pWnd,nCtlColor);
  2591.     }
  2592.  
  2593.  
  2594.  
  2595. //For default processing of WM_DRAWITEM
  2596. LRESULT CSimClientDlg::DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
  2597. {
  2598.     if(nMsg == WM_DRAWITEM)
  2599.         {
  2600.         char szStr[20];
  2601.         LPDRAWITEMSTRUCT lpDrawItem = (LPDRAWITEMSTRUCT)lParam;
  2602.         if(lpDrawItem->CtlType == ODT_BUTTON)
  2603.             {
  2604.             ::GetWindowText(lpDrawItem->hwndItem,szStr,20);
  2605.             if(lstrcmpi( (LPSTR)szStr, (LPSTR)"WMP3DBUTTON") == 0 )
  2606.                 {
  2607.                 BLDDrawStateBitmap(lpDrawItem,"","","","",TRUE);
  2608.                 return TRUE;
  2609.                 }
  2610.             }
  2611.         }
  2612.     return CFormView::DefWindowProc(nMsg,wParam,lParam);
  2613. }
  2614.  
  2615.  
  2616.  
  2617. //To support menues in dialogboxes
  2618. BOOL CSimClientDlg::OnCmdMsg(UINT nID, int nCode, void* pExtra,
  2619.     AFX_CMDHANDLERINFO* pHandlerInfo)
  2620. {
  2621.     //Control command handling ?
  2622.     if (CFormView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
  2623.         return TRUE;
  2624.  
  2625.     // if not, pump through app
  2626.     CWinApp* pApp = AfxGetApp();
  2627.     if (pApp != NULL &&
  2628.       pApp->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
  2629.         return TRUE;
  2630.  
  2631.     return FALSE;
  2632. }
  2633.  
  2634.  
  2635. //This function is from MFC source for class 'CFrameWnd' to
  2636. //support enabling and disabling of menuitems in dialogboxes
  2637. void CSimClientDlg::OnInitMenuPopup(CMenu* pMenu, UINT, BOOL bSysMenu)
  2638. {
  2639.  
  2640.     if (bSysMenu)
  2641.         return;     // don't support system menu
  2642.  
  2643.     if(pMenu == NULL)
  2644.         return;
  2645.  
  2646.     // check the enabled state of various menu items
  2647.     CCmdUI state;
  2648.     state.m_pMenu = pMenu;
  2649.  
  2650.     state.m_nIndexMax = pMenu->GetMenuItemCount();
  2651.     for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
  2652.       state.m_nIndex++)
  2653.     {
  2654.         state.m_nID = pMenu->GetMenuItemID(state.m_nIndex);
  2655.         if (state.m_nID == 0)
  2656.             continue; // menu separator or invalid cmd - ignore it
  2657.  
  2658.         if (state.m_nID == (UINT)-1)
  2659.         {
  2660.             // possibly a popup menu, route to first item of that popup
  2661.             state.m_pSubMenu = pMenu->GetSubMenu(state.m_nIndex);
  2662.             if (state.m_pSubMenu == NULL ||
  2663.                 (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
  2664.                 state.m_nID == (UINT)-1)
  2665.             {
  2666.                 continue;       // first item of popup can't be routed to
  2667.             }
  2668.             state.DoUpdate(this, FALSE);    // popups are never auto disabled
  2669.         }
  2670.         else
  2671.         {
  2672.             // normal menu item
  2673.             // Auto enable/disable if frame window has 'm_bAutoMenuEnable'
  2674.             //    set and command is _not_ a system command.
  2675.             state.m_pSubMenu = NULL;
  2676.             state.DoUpdate(this, ms_bAutoMenuEnable && state.m_nID < 0xF000);
  2677.         }
  2678.     }
  2679. }
  2680.  
  2681.  
  2682.  
  2683. LRESULT CSimClientDlg::OnHelpHitTest(WPARAM wParam, LPARAM lParam)
  2684. {
  2685.     if(ms_HelpID)
  2686.         return ms_HelpID;
  2687.     return CSimClientDlg::OnHelpHitTest(wParam, lParam);
  2688. }
  2689.  
  2690.  
  2691.  
  2692. IMPLEMENT_DYNCREATE(CSimClientDlg, CFormView)
  2693.  
  2694. BEGIN_MESSAGE_MAP(CSimClientDlg, CFormView)
  2695.  
  2696.    ON_WM_CTLCOLOR()
  2697.    ON_WM_PAINT()
  2698.    ON_WM_HSCROLL()
  2699.    ON_WM_VSCROLL()
  2700.    ON_WM_INITMENUPOPUP()
  2701.    ON_MESSAGE(WM_HELPHITTEST, OnHelpHitTest)
  2702.    ON_REGISTERED_MESSAGE(wPrivateMessage,SimHandlePrivateMessage)
  2703.    ON_WM_NCDESTROY()
  2704.  
  2705. END_MESSAGE_MAP()
  2706.  
  2707.  
  2708.  
  2709. // *************************************************************
  2710. // Member function for Class : CSimScrollBar
  2711. // Base Class                : CScrollBar
  2712. // *************************************************************
  2713.  
  2714. CSimScrollBar::CSimScrollBar()
  2715.     : CScrollBar()
  2716. {
  2717.     ms_bTextColor=ms_bBkColor=ms_bBkMode=ms_bDeleteBrush=FALSE;
  2718.     ms_hBrush=0;
  2719.     ms_hFont=0;
  2720. };
  2721.  
  2722.  
  2723.  
  2724. CSimScrollBar::~CSimScrollBar()
  2725. {
  2726.     if(ms_hFont)
  2727.         DeleteObject(ms_hFont);
  2728.     if(ms_bDeleteBrush && ms_hBrush)
  2729.         DeleteObject(ms_hBrush);
  2730.     ms_bDeleteBrush=FALSE;
  2731.     ms_hBrush=0;
  2732.     ms_hFont=0;
  2733. }
  2734.  
  2735.  
  2736.  
  2737. BOOL CSimScrollBar::SimInitCtrlFont(int nHeight,int nWidth,int nEscapement,
  2738.                      int nOrientation,int fnWeight,BYTE fbItalic,BYTE fbUnderline,
  2739.                      BYTE fbStrikeOut,BYTE fbCharSet,BYTE fbOutputPrecision,
  2740.                      BYTE fbClipPrecision,BYTE fbQuality,BYTE fbPitchAndFamily,
  2741.                      char *lpszFace)
  2742.     {
  2743.     ms_hFont=CreateFont(nHeight, nWidth, nEscapement,
  2744.                      nOrientation,fnWeight, fbItalic, fbUnderline,
  2745.                      fbStrikeOut, fbCharSet,fbOutputPrecision,
  2746.                      fbClipPrecision, fbQuality,
  2747.                      fbPitchAndFamily, lpszFace);
  2748.     if(ms_hFont&&GetSafeHwnd())
  2749.         {
  2750.         SendMessage(WM_SETFONT,(WPARAM)ms_hFont,(LPARAM)TRUE);
  2751.         return TRUE;
  2752.         }
  2753.     return FALSE;
  2754.     }
  2755.  
  2756.  
  2757.  
  2758. BOOL CSimScrollBar::SimInitSolidBrush(COLORREF ColorRef)
  2759. {
  2760.     ms_hBrush=CreateSolidBrush(ColorRef);
  2761.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  2762.     return (BOOL) ms_hBrush;
  2763. }
  2764.  
  2765.  
  2766.  
  2767. BOOL CSimScrollBar::SimInitPatternBrush(char *pBitmapName)
  2768. {
  2769.     HBITMAP     hBitmap;
  2770.  
  2771.     hBitmap = BLDLoadBitmap(AfxGetResourceHandle(),pBitmapName);
  2772.     if(hBitmap)
  2773.         {
  2774.         ms_hBrush = CreatePatternBrush(hBitmap);
  2775.         DeleteObject(hBitmap);
  2776.         }
  2777.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  2778.     return (BOOL) ms_hBrush;
  2779. }
  2780.  
  2781.  
  2782.  
  2783. BOOL CSimScrollBar::SimInitStockBrush(int fnObject)
  2784. {
  2785.     ms_hBrush=(HBRUSH)GetStockObject(fnObject);
  2786.     ms_bDeleteBrush = FALSE;
  2787.     return (BOOL) ms_hBrush;
  2788. }
  2789.  
  2790.  
  2791.  
  2792. BOOL CSimScrollBar::SimInitTextColor(BOOL bInTextColor,COLORREF InTextColorRef,BOOL bInBkColor,COLORREF InBkColorRef,int fnInBkMode)
  2793. {
  2794.     ms_bTextColor   = bInTextColor;
  2795.     ms_TextColorRef = InTextColorRef;
  2796.     ms_bBkColor     = bInBkColor;
  2797.     ms_BkColorRef   = InBkColorRef;
  2798.     ms_fnBkMode     = fnInBkMode;
  2799.     ms_bBkMode      = TRUE;
  2800.     return TRUE;
  2801. }
  2802.  
  2803.  
  2804.  
  2805. LRESULT CSimScrollBar::SimHandlePrivateMessage(WPARAM wParam,LPARAM lParam)
  2806. {
  2807.     HBRUSH hBrushRet;
  2808.     HDC    hDC;
  2809.  
  2810. #ifdef WIN32
  2811.     hDC    = (HDC)lParam;
  2812. #else
  2813.     hDC    = (HDC)LOWORD(lParam);
  2814. #endif
  2815.  
  2816.     if(wParam != SIM_CTLCOLOR)
  2817.         return FALSE;
  2818.     if(!ms_hBrush && !ms_bTextColor && !ms_bBkColor && !ms_bBkMode)
  2819.         return NULL;                 //No CtlColor Functionality
  2820.     if(ms_hBrush)
  2821.         hBrushRet = ms_hBrush;
  2822.     else
  2823.         hBrushRet = ::BLDGetGlobalBrushDef(m_hWnd,hDC);
  2824.  
  2825.     if(!hBrushRet)
  2826. #ifdef WIN32
  2827.         hBrushRet=(HBRUSH)::GetClassLong(m_hWnd,GCL_HBRBACKGROUND);
  2828. #else
  2829.         hBrushRet=(HBRUSH)::GetClassWord(m_hWnd,GCW_HBRBACKGROUND);
  2830. #endif
  2831.     if(!hBrushRet)
  2832.         hBrushRet = (HBRUSH)::GetStockObject(WHITE_BRUSH);
  2833.  
  2834.     if(ms_bTextColor)
  2835.         ::SetTextColor(hDC,ms_TextColorRef);
  2836.  
  2837.     if(ms_bBkColor)
  2838.         ::SetBkColor(hDC,ms_BkColorRef);
  2839.  
  2840.     if(ms_bBkMode)
  2841.         ::SetBkMode(hDC,ms_fnBkMode);
  2842.  
  2843. #ifdef WIN32
  2844.     return (LRESULT)hBrushRet;
  2845. #else
  2846.     return MAKELONG(hBrushRet,0);
  2847. #endif
  2848. }
  2849.  
  2850.  
  2851. IMPLEMENT_DYNCREATE(CSimScrollBar, CScrollBar)
  2852.  
  2853. BEGIN_MESSAGE_MAP(CSimScrollBar, CScrollBar)
  2854.  
  2855.    ON_REGISTERED_MESSAGE(wPrivateMessage,SimHandlePrivateMessage)
  2856.  
  2857. END_MESSAGE_MAP()
  2858.  
  2859.  
  2860.  
  2861. // *************************************************************
  2862. // Member function for Class : CSimStatic
  2863. // Base Class                : CStatic
  2864. // *************************************************************
  2865.  
  2866. CSimStatic::CSimStatic()
  2867.     : CStatic()
  2868. {
  2869.     ms_bTextColor=ms_bBkColor=ms_bBkMode=ms_bDeleteBrush=FALSE;
  2870.     ms_hBrush=0;
  2871.     ms_hFont=0;
  2872. };
  2873.  
  2874.  
  2875.  
  2876. CSimStatic::~CSimStatic()
  2877. {
  2878.     if(ms_hFont)
  2879.         DeleteObject(ms_hFont);
  2880.     if(ms_bDeleteBrush && ms_hBrush)
  2881.         DeleteObject(ms_hBrush);
  2882.     ms_bDeleteBrush=FALSE;
  2883.     ms_hBrush=0;
  2884.     ms_hFont=0;
  2885. }
  2886.  
  2887.  
  2888.  
  2889. BOOL CSimStatic::SimInitCtrlFont(int nHeight,int nWidth,int nEscapement,
  2890.                      int nOrientation,int fnWeight,BYTE fbItalic,BYTE fbUnderline,
  2891.                      BYTE fbStrikeOut,BYTE fbCharSet,BYTE fbOutputPrecision,
  2892.                      BYTE fbClipPrecision,BYTE fbQuality,BYTE fbPitchAndFamily,
  2893.                      char *lpszFace)
  2894.     {
  2895.     ms_hFont=CreateFont(nHeight, nWidth, nEscapement,
  2896.                      nOrientation,fnWeight, fbItalic, fbUnderline,
  2897.                      fbStrikeOut, fbCharSet,fbOutputPrecision,
  2898.                      fbClipPrecision, fbQuality,
  2899.                      fbPitchAndFamily, lpszFace);
  2900.     if(ms_hFont&&GetSafeHwnd())
  2901.         {
  2902.         SendMessage(WM_SETFONT,(WPARAM)ms_hFont,(LPARAM)TRUE);
  2903.         return TRUE;
  2904.         }
  2905.     return FALSE;
  2906.     }
  2907.  
  2908.  
  2909.  
  2910. BOOL CSimStatic::SimInitSolidBrush(COLORREF ColorRef)
  2911. {
  2912.     ms_hBrush=CreateSolidBrush(ColorRef);
  2913.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  2914.     return (BOOL) ms_hBrush;
  2915. }
  2916.  
  2917.  
  2918.  
  2919. BOOL CSimStatic::SimInitPatternBrush(char *pBitmapName)
  2920. {
  2921.     HBITMAP     hBitmap;
  2922.  
  2923.     hBitmap = BLDLoadBitmap(AfxGetResourceHandle(),pBitmapName);
  2924.     if(hBitmap)
  2925.         {
  2926.         ms_hBrush = CreatePatternBrush(hBitmap);
  2927.         DeleteObject(hBitmap);
  2928.         }
  2929.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  2930.     return (BOOL) ms_hBrush;
  2931. }
  2932.  
  2933.  
  2934.  
  2935. BOOL CSimStatic::SimInitStockBrush(int fnObject)
  2936. {
  2937.     ms_hBrush=(HBRUSH)GetStockObject(fnObject);
  2938.     ms_bDeleteBrush = FALSE;
  2939.     return (BOOL) ms_hBrush;
  2940. }
  2941.  
  2942.  
  2943.  
  2944. BOOL CSimStatic::SimInitTextColor(BOOL bInTextColor,COLORREF InTextColorRef,BOOL bInBkColor,COLORREF InBkColorRef,int fnInBkMode)
  2945. {
  2946.     ms_bTextColor   = bInTextColor;
  2947.     ms_TextColorRef = InTextColorRef;
  2948.     ms_bBkColor     = bInBkColor;
  2949.     ms_BkColorRef   = InBkColorRef;
  2950.     ms_fnBkMode     = fnInBkMode;
  2951.     ms_bBkMode      = TRUE;
  2952.     return TRUE;
  2953. }
  2954.  
  2955.  
  2956.  
  2957. LRESULT CSimStatic::SimHandlePrivateMessage(WPARAM wParam,LPARAM lParam)
  2958. {
  2959.     HBRUSH hBrushRet;
  2960.     HDC    hDC;
  2961.  
  2962. #ifdef WIN32
  2963.     hDC    = (HDC)lParam;
  2964. #else
  2965.     hDC    = (HDC)LOWORD(lParam);
  2966. #endif
  2967.  
  2968.     if(wParam != SIM_CTLCOLOR)
  2969.         return FALSE;
  2970.     if(!ms_hBrush && !ms_bTextColor && !ms_bBkColor && !ms_bBkMode)
  2971.         return NULL;                 //No CtlColor Functionality
  2972.     if(ms_hBrush)
  2973.         hBrushRet = ms_hBrush;
  2974.     else
  2975.         hBrushRet = ::BLDGetGlobalBrushDef(m_hWnd,hDC);
  2976.  
  2977.     if(!hBrushRet)
  2978. #ifdef WIN32
  2979.         hBrushRet=(HBRUSH)::GetClassLong(m_hWnd,GCL_HBRBACKGROUND);
  2980. #else
  2981.         hBrushRet=(HBRUSH)::GetClassWord(m_hWnd,GCW_HBRBACKGROUND);
  2982. #endif
  2983.     if(!hBrushRet)
  2984.         hBrushRet = (HBRUSH)::GetStockObject(WHITE_BRUSH);
  2985.  
  2986.     if(ms_bTextColor)
  2987.         ::SetTextColor(hDC,ms_TextColorRef);
  2988.  
  2989.     if(ms_bBkColor)
  2990.         ::SetBkColor(hDC,ms_BkColorRef);
  2991.  
  2992.     if(ms_bBkMode)
  2993.         ::SetBkMode(hDC,ms_fnBkMode);
  2994.  
  2995. #ifdef WIN32
  2996.     return (LRESULT)hBrushRet;
  2997. #else
  2998.     return MAKELONG(hBrushRet,0);
  2999. #endif
  3000. }
  3001.  
  3002.  
  3003. IMPLEMENT_DYNCREATE(CSimStatic, CStatic)
  3004.  
  3005. BEGIN_MESSAGE_MAP(CSimStatic, CStatic)
  3006.  
  3007.    ON_REGISTERED_MESSAGE(wPrivateMessage,SimHandlePrivateMessage)
  3008.  
  3009. END_MESSAGE_MAP()
  3010.  
  3011.  
  3012.  
  3013. // *************************************************************
  3014. // Member function for Class : CSimEdit
  3015. // Base Class                : CEdit
  3016. // *************************************************************
  3017.  
  3018. CSimEdit::CSimEdit()
  3019.     : CEdit()
  3020. {
  3021.     ms_bTextColor=ms_bBkColor=ms_bBkMode=ms_bDeleteBrush=FALSE;
  3022.     ms_hBrush=0;
  3023.     ms_hFont=0;
  3024. };
  3025.  
  3026.  
  3027.  
  3028. CSimEdit::~CSimEdit()
  3029. {
  3030.     if(ms_hFont)
  3031.         DeleteObject(ms_hFont);
  3032.     if(ms_bDeleteBrush && ms_hBrush)
  3033.         DeleteObject(ms_hBrush);
  3034.     ms_bDeleteBrush=FALSE;
  3035.     ms_hBrush=0;
  3036.     ms_hFont=0;
  3037. }
  3038.  
  3039.  
  3040.  
  3041. BOOL CSimEdit::SimInitCtrlFont(int nHeight,int nWidth,int nEscapement,
  3042.                      int nOrientation,int fnWeight,BYTE fbItalic,BYTE fbUnderline,
  3043.                      BYTE fbStrikeOut,BYTE fbCharSet,BYTE fbOutputPrecision,
  3044.                      BYTE fbClipPrecision,BYTE fbQuality,BYTE fbPitchAndFamily,
  3045.                      char *lpszFace)
  3046.     {
  3047.     ms_hFont=CreateFont(nHeight, nWidth, nEscapement,
  3048.                      nOrientation,fnWeight, fbItalic, fbUnderline,
  3049.                      fbStrikeOut, fbCharSet,fbOutputPrecision,
  3050.                      fbClipPrecision, fbQuality,
  3051.                      fbPitchAndFamily, lpszFace);
  3052.     if(ms_hFont&&GetSafeHwnd())
  3053.         {
  3054.         SendMessage(WM_SETFONT,(WPARAM)ms_hFont,(LPARAM)TRUE);
  3055.         return TRUE;
  3056.         }
  3057.     return FALSE;
  3058.     }
  3059.  
  3060.  
  3061.  
  3062. BOOL CSimEdit::SimInitSolidBrush(COLORREF ColorRef)
  3063. {
  3064.     ms_hBrush=CreateSolidBrush(ColorRef);
  3065.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  3066.     return (BOOL) ms_hBrush;
  3067. }
  3068.  
  3069.  
  3070.  
  3071. BOOL CSimEdit::SimInitPatternBrush(char *pBitmapName)
  3072. {
  3073.     HBITMAP     hBitmap;
  3074.  
  3075.     hBitmap = BLDLoadBitmap(AfxGetResourceHandle(),pBitmapName);
  3076.     if(hBitmap)
  3077.         {
  3078.         ms_hBrush = CreatePatternBrush(hBitmap);
  3079.         DeleteObject(hBitmap);
  3080.         }
  3081.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  3082.     return (BOOL) ms_hBrush;
  3083. }
  3084.  
  3085.  
  3086.  
  3087. BOOL CSimEdit::SimInitStockBrush(int fnObject)
  3088. {
  3089.     ms_hBrush=(HBRUSH)GetStockObject(fnObject);
  3090.     ms_bDeleteBrush = FALSE;
  3091.     return (BOOL) ms_hBrush;
  3092. }
  3093.  
  3094.  
  3095.  
  3096. BOOL CSimEdit::SimInitTextColor(BOOL bInTextColor,COLORREF InTextColorRef,BOOL bInBkColor,COLORREF InBkColorRef,int fnInBkMode)
  3097. {
  3098.     ms_bTextColor   = bInTextColor;
  3099.     ms_TextColorRef = InTextColorRef;
  3100.     ms_bBkColor     = bInBkColor;
  3101.     ms_BkColorRef   = InBkColorRef;
  3102.     ms_fnBkMode     = fnInBkMode;
  3103.     ms_bBkMode      = TRUE;
  3104.     return TRUE;
  3105. }
  3106.  
  3107.  
  3108.  
  3109. LRESULT CSimEdit::SimHandlePrivateMessage(WPARAM wParam,LPARAM lParam)
  3110. {
  3111.     HBRUSH hBrushRet;
  3112.     HDC    hDC;
  3113.  
  3114. #ifdef WIN32
  3115.     hDC    = (HDC)lParam;
  3116. #else
  3117.     hDC    = (HDC)LOWORD(lParam);
  3118. #endif
  3119.  
  3120.     if(wParam != SIM_CTLCOLOR)
  3121.         return FALSE;
  3122.     if(!ms_hBrush && !ms_bTextColor && !ms_bBkColor && !ms_bBkMode)
  3123.         return NULL;                 //No CtlColor Functionality
  3124.     if(ms_hBrush)
  3125.         hBrushRet = ms_hBrush;
  3126.     else
  3127.         hBrushRet = ::BLDGetGlobalBrushDef(m_hWnd,hDC);
  3128.  
  3129.     if(!hBrushRet)
  3130. #ifdef WIN32
  3131.         hBrushRet=(HBRUSH)::GetClassLong(m_hWnd,GCL_HBRBACKGROUND);
  3132. #else
  3133.         hBrushRet=(HBRUSH)::GetClassWord(m_hWnd,GCW_HBRBACKGROUND);
  3134. #endif
  3135.     if(!hBrushRet)
  3136.         hBrushRet = (HBRUSH)::GetStockObject(WHITE_BRUSH);
  3137.  
  3138.     if(ms_bTextColor)
  3139.         ::SetTextColor(hDC,ms_TextColorRef);
  3140.  
  3141.     if(ms_bBkColor)
  3142.         ::SetBkColor(hDC,ms_BkColorRef);
  3143.  
  3144.     if(ms_bBkMode)
  3145.         ::SetBkMode(hDC,ms_fnBkMode);
  3146.  
  3147. #ifdef WIN32
  3148.     return (LRESULT)hBrushRet;
  3149. #else
  3150.     return MAKELONG(hBrushRet,0);
  3151. #endif
  3152. }
  3153.  
  3154.  
  3155. IMPLEMENT_DYNCREATE(CSimEdit, CEdit)
  3156.  
  3157. BEGIN_MESSAGE_MAP(CSimEdit, CEdit)
  3158.  
  3159.    ON_REGISTERED_MESSAGE(wPrivateMessage,SimHandlePrivateMessage)
  3160.  
  3161. END_MESSAGE_MAP()
  3162.  
  3163.  
  3164.  
  3165. // *************************************************************
  3166. // Member function for Class : CSimListBox
  3167. // Base Class                : CListBox
  3168. // *************************************************************
  3169.  
  3170. CSimListBox::CSimListBox()
  3171.     : CListBox()
  3172. {
  3173.     ms_bTextColor=ms_bBkColor=ms_bBkMode=ms_bDeleteBrush=FALSE;
  3174.     ms_hBrush=0;
  3175.     ms_hFont=0;
  3176. };
  3177.  
  3178.  
  3179.  
  3180. CSimListBox::~CSimListBox()
  3181. {
  3182.     if(ms_hFont)
  3183.         DeleteObject(ms_hFont);
  3184.     if(ms_bDeleteBrush && ms_hBrush)
  3185.         DeleteObject(ms_hBrush);
  3186.     ms_bDeleteBrush=FALSE;
  3187.     ms_hBrush=0;
  3188.     ms_hFont=0;
  3189. }
  3190.  
  3191.  
  3192.  
  3193. BOOL CSimListBox::SimInitCtrlFont(int nHeight,int nWidth,int nEscapement,
  3194.                      int nOrientation,int fnWeight,BYTE fbItalic,BYTE fbUnderline,
  3195.                      BYTE fbStrikeOut,BYTE fbCharSet,BYTE fbOutputPrecision,
  3196.                      BYTE fbClipPrecision,BYTE fbQuality,BYTE fbPitchAndFamily,
  3197.                      char *lpszFace)
  3198.     {
  3199.     ms_hFont=CreateFont(nHeight, nWidth, nEscapement,
  3200.                      nOrientation,fnWeight, fbItalic, fbUnderline,
  3201.                      fbStrikeOut, fbCharSet,fbOutputPrecision,
  3202.                      fbClipPrecision, fbQuality,
  3203.                      fbPitchAndFamily, lpszFace);
  3204.     if(ms_hFont&&GetSafeHwnd())
  3205.         {
  3206.         SendMessage(WM_SETFONT,(WPARAM)ms_hFont,(LPARAM)TRUE);
  3207.         return TRUE;
  3208.         }
  3209.     return FALSE;
  3210.     }
  3211.  
  3212.  
  3213.  
  3214. BOOL CSimListBox::SimInitSolidBrush(COLORREF ColorRef)
  3215. {
  3216.     ms_hBrush=CreateSolidBrush(ColorRef);
  3217.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  3218.     return (BOOL) ms_hBrush;
  3219. }
  3220.  
  3221.  
  3222.  
  3223. BOOL CSimListBox::SimInitPatternBrush(char *pBitmapName)
  3224. {
  3225.     HBITMAP     hBitmap;
  3226.  
  3227.     hBitmap = BLDLoadBitmap(AfxGetResourceHandle(),pBitmapName);
  3228.     if(hBitmap)
  3229.         {
  3230.         ms_hBrush = CreatePatternBrush(hBitmap);
  3231.         DeleteObject(hBitmap);
  3232.         }
  3233.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  3234.     return (BOOL) ms_hBrush;
  3235. }
  3236.  
  3237.  
  3238.  
  3239. BOOL CSimListBox::SimInitStockBrush(int fnObject)
  3240. {
  3241.     ms_hBrush=(HBRUSH)GetStockObject(fnObject);
  3242.     ms_bDeleteBrush = FALSE;
  3243.     return (BOOL) ms_hBrush;
  3244. }
  3245.  
  3246.  
  3247.  
  3248. BOOL CSimListBox::SimInitTextColor(BOOL bInTextColor,COLORREF InTextColorRef,BOOL bInBkColor,COLORREF InBkColorRef,int fnInBkMode)
  3249. {
  3250.     ms_bTextColor   = bInTextColor;
  3251.     ms_TextColorRef = InTextColorRef;
  3252.     ms_bBkColor     = bInBkColor;
  3253.     ms_BkColorRef   = InBkColorRef;
  3254.     ms_fnBkMode     = fnInBkMode;
  3255.     ms_bBkMode      = TRUE;
  3256.     return TRUE;
  3257. }
  3258.  
  3259.  
  3260.  
  3261. LRESULT CSimListBox::SimHandlePrivateMessage(WPARAM wParam,LPARAM lParam)
  3262. {
  3263.     HBRUSH hBrushRet;
  3264.     HDC    hDC;
  3265.  
  3266. #ifdef WIN32
  3267.     hDC    = (HDC)lParam;
  3268. #else
  3269.     hDC    = (HDC)LOWORD(lParam);
  3270. #endif
  3271.  
  3272.     if(wParam != SIM_CTLCOLOR)
  3273.         return FALSE;
  3274.     if(!ms_hBrush && !ms_bTextColor && !ms_bBkColor && !ms_bBkMode)
  3275.         return NULL;                 //No CtlColor Functionality
  3276.     if(ms_hBrush)
  3277.         hBrushRet = ms_hBrush;
  3278.     else
  3279.         hBrushRet = ::BLDGetGlobalBrushDef(m_hWnd,hDC);
  3280.  
  3281.     if(!hBrushRet)
  3282. #ifdef WIN32
  3283.         hBrushRet=(HBRUSH)::GetClassLong(m_hWnd,GCL_HBRBACKGROUND);
  3284. #else
  3285.         hBrushRet=(HBRUSH)::GetClassWord(m_hWnd,GCW_HBRBACKGROUND);
  3286. #endif
  3287.     if(!hBrushRet)
  3288.         hBrushRet = (HBRUSH)::GetStockObject(WHITE_BRUSH);
  3289.  
  3290.     if(ms_bTextColor)
  3291.         ::SetTextColor(hDC,ms_TextColorRef);
  3292.  
  3293.     if(ms_bBkColor)
  3294.         ::SetBkColor(hDC,ms_BkColorRef);
  3295.  
  3296.     if(ms_bBkMode)
  3297.         ::SetBkMode(hDC,ms_fnBkMode);
  3298.  
  3299. #ifdef WIN32
  3300.     return (LRESULT)hBrushRet;
  3301. #else
  3302.     return MAKELONG(hBrushRet,0);
  3303. #endif
  3304. }
  3305.  
  3306.  
  3307. IMPLEMENT_DYNCREATE(CSimListBox, CListBox)
  3308.  
  3309. BEGIN_MESSAGE_MAP(CSimListBox, CListBox)
  3310.  
  3311.    ON_REGISTERED_MESSAGE(wPrivateMessage,SimHandlePrivateMessage)
  3312.  
  3313. END_MESSAGE_MAP()
  3314.  
  3315.  
  3316.  
  3317. // *************************************************************
  3318. // Member function for Class : CSimComboBox
  3319. // Base Class                : CComboBox
  3320. // *************************************************************
  3321.  
  3322. CSimComboBox::CSimComboBox()
  3323.     : CComboBox()
  3324. {
  3325.     ms_bTextColor=ms_bBkColor=ms_bBkMode=ms_bDeleteBrush=FALSE;
  3326.     ms_hBrush=0;
  3327.     ms_hFont=0;
  3328. };
  3329.  
  3330.  
  3331.  
  3332. CSimComboBox::~CSimComboBox()
  3333. {
  3334.     if(ms_hFont)
  3335.         DeleteObject(ms_hFont);
  3336.     if(ms_bDeleteBrush && ms_hBrush)
  3337.         DeleteObject(ms_hBrush);
  3338.     ms_bDeleteBrush=FALSE;
  3339.     ms_hBrush=0;
  3340.     ms_hFont=0;
  3341. }
  3342.  
  3343.  
  3344.  
  3345. BOOL CSimComboBox::SimInitCtrlFont(int nHeight,int nWidth,int nEscapement,
  3346.                      int nOrientation,int fnWeight,BYTE fbItalic,BYTE fbUnderline,
  3347.                      BYTE fbStrikeOut,BYTE fbCharSet,BYTE fbOutputPrecision,
  3348.                      BYTE fbClipPrecision,BYTE fbQuality,BYTE fbPitchAndFamily,
  3349.                      char *lpszFace)
  3350.     {
  3351.     ms_hFont=CreateFont(nHeight, nWidth, nEscapement,
  3352.                      nOrientation,fnWeight, fbItalic, fbUnderline,
  3353.                      fbStrikeOut, fbCharSet,fbOutputPrecision,
  3354.                      fbClipPrecision, fbQuality,
  3355.                      fbPitchAndFamily, lpszFace);
  3356.     if(ms_hFont&&GetSafeHwnd())
  3357.         {
  3358.         SendMessage(WM_SETFONT,(WPARAM)ms_hFont,(LPARAM)TRUE);
  3359.         return TRUE;
  3360.         }
  3361.     return FALSE;
  3362.     }
  3363.  
  3364.  
  3365.  
  3366. BOOL CSimComboBox::SimInitSolidBrush(COLORREF ColorRef)
  3367. {
  3368.     ms_hBrush=CreateSolidBrush(ColorRef);
  3369.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  3370.     return (BOOL) ms_hBrush;
  3371. }
  3372.  
  3373.  
  3374.  
  3375. BOOL CSimComboBox::SimInitPatternBrush(char *pBitmapName)
  3376. {
  3377.     HBITMAP     hBitmap;
  3378.  
  3379.     hBitmap = BLDLoadBitmap(AfxGetResourceHandle(),pBitmapName);
  3380.     if(hBitmap)
  3381.         {
  3382.         ms_hBrush = CreatePatternBrush(hBitmap);
  3383.         DeleteObject(hBitmap);
  3384.         }
  3385.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  3386.     return (BOOL) ms_hBrush;
  3387. }
  3388.  
  3389.  
  3390.  
  3391. BOOL CSimComboBox::SimInitStockBrush(int fnObject)
  3392. {
  3393.     ms_hBrush=(HBRUSH)GetStockObject(fnObject);
  3394.     ms_bDeleteBrush = FALSE;
  3395.     return (BOOL) ms_hBrush;
  3396. }
  3397.  
  3398.  
  3399.  
  3400. BOOL CSimComboBox::SimInitTextColor(BOOL bInTextColor,COLORREF InTextColorRef,BOOL bInBkColor,COLORREF InBkColorRef,int fnInBkMode)
  3401. {
  3402.     ms_bTextColor   = bInTextColor;
  3403.     ms_TextColorRef = InTextColorRef;
  3404.     ms_bBkColor     = bInBkColor;
  3405.     ms_BkColorRef   = InBkColorRef;
  3406.     ms_fnBkMode     = fnInBkMode;
  3407.     ms_bBkMode      = TRUE;
  3408.     return TRUE;
  3409. }
  3410.  
  3411.  
  3412.  
  3413. LRESULT CSimComboBox::SimHandlePrivateMessage(WPARAM wParam,LPARAM lParam)
  3414. {
  3415.     HBRUSH hBrushRet;
  3416.     HDC    hDC;
  3417.  
  3418. #ifdef WIN32
  3419.     hDC    = (HDC)lParam;
  3420. #else
  3421.     hDC    = (HDC)LOWORD(lParam);
  3422. #endif
  3423.  
  3424.     if(wParam != SIM_CTLCOLOR)
  3425.         return FALSE;
  3426.     if(!ms_hBrush && !ms_bTextColor && !ms_bBkColor && !ms_bBkMode)
  3427.         return NULL;                 //No CtlColor Functionality
  3428.     if(ms_hBrush)
  3429.         hBrushRet = ms_hBrush;
  3430.     else
  3431.         hBrushRet = ::BLDGetGlobalBrushDef(m_hWnd,hDC);
  3432.  
  3433.     if(!hBrushRet)
  3434. #ifdef WIN32
  3435.         hBrushRet=(HBRUSH)::GetClassLong(m_hWnd,GCL_HBRBACKGROUND);
  3436. #else
  3437.         hBrushRet=(HBRUSH)::GetClassWord(m_hWnd,GCW_HBRBACKGROUND);
  3438. #endif
  3439.     if(!hBrushRet)
  3440.         hBrushRet = (HBRUSH)::GetStockObject(WHITE_BRUSH);
  3441.  
  3442.     if(ms_bTextColor)
  3443.         ::SetTextColor(hDC,ms_TextColorRef);
  3444.  
  3445.     if(ms_bBkColor)
  3446.         ::SetBkColor(hDC,ms_BkColorRef);
  3447.  
  3448.     if(ms_bBkMode)
  3449.         ::SetBkMode(hDC,ms_fnBkMode);
  3450.  
  3451. #ifdef WIN32
  3452.     return (LRESULT)hBrushRet;
  3453. #else
  3454.     return MAKELONG(hBrushRet,0);
  3455. #endif
  3456. }
  3457.  
  3458.  
  3459. IMPLEMENT_DYNCREATE(CSimComboBox, CComboBox)
  3460.  
  3461. BEGIN_MESSAGE_MAP(CSimComboBox, CComboBox)
  3462.  
  3463.    ON_REGISTERED_MESSAGE(wPrivateMessage,SimHandlePrivateMessage)
  3464.  
  3465. END_MESSAGE_MAP()
  3466.  
  3467.  
  3468.  
  3469. // *************************************************************
  3470. // Member function for Class : CSimButton
  3471. // Base Class                : CButton
  3472. // *************************************************************
  3473.  
  3474. CSimButton::CSimButton()
  3475.     : CButton()
  3476. {
  3477.     ms_bTextColor=ms_bBkColor=ms_bBkMode=ms_bDeleteBrush=FALSE;
  3478.     ms_hBrush=0;
  3479.     ms_hFont=0;
  3480. };
  3481.  
  3482.  
  3483.  
  3484. CSimButton::~CSimButton()
  3485. {
  3486.     if(ms_hFont)
  3487.         DeleteObject(ms_hFont);
  3488.     if(ms_bDeleteBrush && ms_hBrush)
  3489.         DeleteObject(ms_hBrush);
  3490.     ms_bDeleteBrush=FALSE;
  3491.     ms_hBrush=0;
  3492.     ms_hFont=0;
  3493. }
  3494.  
  3495.  
  3496.  
  3497. BOOL CSimButton::SimInitCtrlFont(int nHeight,int nWidth,int nEscapement,
  3498.                      int nOrientation,int fnWeight,BYTE fbItalic,BYTE fbUnderline,
  3499.                      BYTE fbStrikeOut,BYTE fbCharSet,BYTE fbOutputPrecision,
  3500.                      BYTE fbClipPrecision,BYTE fbQuality,BYTE fbPitchAndFamily,
  3501.                      char *lpszFace)
  3502.     {
  3503.     ms_hFont=CreateFont(nHeight, nWidth, nEscapement,
  3504.                      nOrientation,fnWeight, fbItalic, fbUnderline,
  3505.                      fbStrikeOut, fbCharSet,fbOutputPrecision,
  3506.                      fbClipPrecision, fbQuality,
  3507.                      fbPitchAndFamily, lpszFace);
  3508.     if(ms_hFont&&GetSafeHwnd())
  3509.         {
  3510.         SendMessage(WM_SETFONT,(WPARAM)ms_hFont,(LPARAM)TRUE);
  3511.         return TRUE;
  3512.         }
  3513.     return FALSE;
  3514.     }
  3515.  
  3516.  
  3517.  
  3518. BOOL CSimButton::SimInitSolidBrush(COLORREF ColorRef)
  3519. {
  3520.     ms_hBrush=CreateSolidBrush(ColorRef);
  3521.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  3522.     return (BOOL) ms_hBrush;
  3523. }
  3524.  
  3525.  
  3526.  
  3527. BOOL CSimButton::SimInitPatternBrush(char *pBitmapName)
  3528. {
  3529.     HBITMAP     hBitmap;
  3530.  
  3531.     hBitmap = BLDLoadBitmap(AfxGetResourceHandle(),pBitmapName);
  3532.     if(hBitmap)
  3533.         {
  3534.         ms_hBrush = CreatePatternBrush(hBitmap);
  3535.         DeleteObject(hBitmap);
  3536.         }
  3537.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  3538.     return (BOOL) ms_hBrush;
  3539. }
  3540.  
  3541.  
  3542.  
  3543. BOOL CSimButton::SimInitStockBrush(int fnObject)
  3544. {
  3545.     ms_hBrush=(HBRUSH)GetStockObject(fnObject);
  3546.     ms_bDeleteBrush = FALSE;
  3547.     return (BOOL) ms_hBrush;
  3548. }
  3549.  
  3550.  
  3551.  
  3552. BOOL CSimButton::SimInitTextColor(BOOL bInTextColor,COLORREF InTextColorRef,BOOL bInBkColor,COLORREF InBkColorRef,int fnInBkMode)
  3553. {
  3554.     ms_bTextColor   = bInTextColor;
  3555.     ms_TextColorRef = InTextColorRef;
  3556.     ms_bBkColor     = bInBkColor;
  3557.     ms_BkColorRef   = InBkColorRef;
  3558.     ms_fnBkMode     = fnInBkMode;
  3559.     ms_bBkMode      = TRUE;
  3560.     return TRUE;
  3561. }
  3562.  
  3563.  
  3564.  
  3565. LRESULT CSimButton::SimHandlePrivateMessage(WPARAM wParam,LPARAM lParam)
  3566. {
  3567.     HBRUSH hBrushRet;
  3568.     HDC    hDC;
  3569.  
  3570. #ifdef WIN32
  3571.     hDC    = (HDC)lParam;
  3572. #else
  3573.     hDC    = (HDC)LOWORD(lParam);
  3574. #endif
  3575.  
  3576.     if(wParam != SIM_CTLCOLOR)
  3577.         return FALSE;
  3578.     if(!ms_hBrush && !ms_bTextColor && !ms_bBkColor && !ms_bBkMode)
  3579.         return NULL;                 //No CtlColor Functionality
  3580.     if(ms_hBrush)
  3581.         hBrushRet = ms_hBrush;
  3582.     else
  3583.         hBrushRet = ::BLDGetGlobalBrushDef(m_hWnd,hDC);
  3584.  
  3585.     if(!hBrushRet)
  3586. #ifdef WIN32
  3587.         hBrushRet=(HBRUSH)::GetClassLong(m_hWnd,GCL_HBRBACKGROUND);
  3588. #else
  3589.         hBrushRet=(HBRUSH)::GetClassWord(m_hWnd,GCW_HBRBACKGROUND);
  3590. #endif
  3591.     if(!hBrushRet)
  3592.         hBrushRet = (HBRUSH)::GetStockObject(WHITE_BRUSH);
  3593.  
  3594.     if(ms_bTextColor)
  3595.         ::SetTextColor(hDC,ms_TextColorRef);
  3596.  
  3597.     if(ms_bBkColor)
  3598.         ::SetBkColor(hDC,ms_BkColorRef);
  3599.  
  3600.     if(ms_bBkMode)
  3601.         ::SetBkMode(hDC,ms_fnBkMode);
  3602.  
  3603. #ifdef WIN32
  3604.     return (LRESULT)hBrushRet;
  3605. #else
  3606.     return MAKELONG(hBrushRet,0);
  3607. #endif
  3608. }
  3609.  
  3610.  
  3611. IMPLEMENT_DYNCREATE(CSimButton, CButton)
  3612.  
  3613. BEGIN_MESSAGE_MAP(CSimButton, CButton)
  3614.  
  3615.    ON_REGISTERED_MESSAGE(wPrivateMessage,SimHandlePrivateMessage)
  3616.  
  3617. END_MESSAGE_MAP()
  3618.  
  3619.  
  3620.  
  3621. // *************************************************************
  3622. // Member function for Class : CSimCustom
  3623. // Base Class                : CWnd
  3624. // *************************************************************
  3625.  
  3626. CSimCustom::CSimCustom()
  3627.     : CWnd()
  3628. {
  3629.     ms_bTextColor=ms_bBkColor=ms_bBkMode=ms_bDeleteBrush=FALSE;
  3630.     ms_hBrush=0;
  3631.     ms_hFont=0;
  3632. };
  3633.  
  3634.  
  3635.  
  3636. CSimCustom::~CSimCustom()
  3637. {
  3638.     if(ms_hFont)
  3639.         DeleteObject(ms_hFont);
  3640.     if(ms_bDeleteBrush && ms_hBrush)
  3641.         DeleteObject(ms_hBrush);
  3642.     ms_bDeleteBrush=FALSE;
  3643.     ms_hBrush=0;
  3644.     ms_hFont=0;
  3645. }
  3646.  
  3647.  
  3648.  
  3649. BOOL CSimCustom::SimInitCtrlFont(int nHeight,int nWidth,int nEscapement,
  3650.                      int nOrientation,int fnWeight,BYTE fbItalic,BYTE fbUnderline,
  3651.                      BYTE fbStrikeOut,BYTE fbCharSet,BYTE fbOutputPrecision,
  3652.                      BYTE fbClipPrecision,BYTE fbQuality,BYTE fbPitchAndFamily,
  3653.                      char *lpszFace)
  3654.     {
  3655.     ms_hFont=CreateFont(nHeight, nWidth, nEscapement,
  3656.                      nOrientation,fnWeight, fbItalic, fbUnderline,
  3657.                      fbStrikeOut, fbCharSet,fbOutputPrecision,
  3658.                      fbClipPrecision, fbQuality,
  3659.                      fbPitchAndFamily, lpszFace);
  3660.     if(ms_hFont&&GetSafeHwnd())
  3661.         {
  3662.         SendMessage(WM_SETFONT,(WPARAM)ms_hFont,(LPARAM)TRUE);
  3663.         return TRUE;
  3664.         }
  3665.     return FALSE;
  3666.     }
  3667.  
  3668.  
  3669.  
  3670. BOOL CSimCustom::SimInitSolidBrush(COLORREF ColorRef)
  3671. {
  3672.     ms_hBrush=CreateSolidBrush(ColorRef);
  3673.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  3674.     return (BOOL) ms_hBrush;
  3675. }
  3676.  
  3677.  
  3678.  
  3679. BOOL CSimCustom::SimInitPatternBrush(char *pBitmapName)
  3680. {
  3681.     HBITMAP     hBitmap;
  3682.  
  3683.     hBitmap = BLDLoadBitmap(AfxGetResourceHandle(),pBitmapName);
  3684.     if(hBitmap)
  3685.         {
  3686.         ms_hBrush = CreatePatternBrush(hBitmap);
  3687.         DeleteObject(hBitmap);
  3688.         }
  3689.     ms_bDeleteBrush = (BOOL) ms_hBrush;
  3690.     return (BOOL) ms_hBrush;
  3691. }
  3692.  
  3693.  
  3694.  
  3695. BOOL CSimCustom::SimInitStockBrush(int fnObject)
  3696. {
  3697.     ms_hBrush=(HBRUSH)GetStockObject(fnObject);
  3698.     ms_bDeleteBrush = FALSE;
  3699.     return (BOOL) ms_hBrush;
  3700. }
  3701.  
  3702.  
  3703.  
  3704. BOOL CSimCustom::SimInitTextColor(BOOL bInTextColor,COLORREF InTextColorRef,BOOL bInBkColor,COLORREF InBkColorRef,int fnInBkMode)
  3705. {
  3706.     ms_bTextColor   = bInTextColor;
  3707.     ms_TextColorRef = InTextColorRef;
  3708.     ms_bBkColor     = bInBkColor;
  3709.     ms_BkColorRef   = InBkColorRef;
  3710.     ms_fnBkMode     = fnInBkMode;
  3711.     ms_bBkMode      = TRUE;
  3712.     return TRUE;
  3713. }
  3714.  
  3715.  
  3716.  
  3717. LRESULT CSimCustom::SimHandlePrivateMessage(WPARAM wParam,LPARAM lParam)
  3718. {
  3719.     HBRUSH hBrushRet;
  3720.     HDC    hDC;
  3721.  
  3722. #ifdef WIN32
  3723.     hDC    = (HDC)lParam;
  3724. #else
  3725.     hDC    = (HDC)LOWORD(lParam);
  3726. #endif
  3727.  
  3728.     if(wParam != SIM_CTLCOLOR)
  3729.         return FALSE;
  3730.     if(!ms_hBrush && !ms_bTextColor && !ms_bBkColor && !ms_bBkMode)
  3731.         return NULL;                 //No CtlColor Functionality
  3732.     if(ms_hBrush)
  3733.         hBrushRet = ms_hBrush;
  3734.     else
  3735.         hBrushRet = ::BLDGetGlobalBrushDef(m_hWnd,hDC);
  3736.  
  3737.     if(!hBrushRet)
  3738. #ifdef WIN32
  3739.         hBrushRet=(HBRUSH)::GetClassLong(m_hWnd,GCL_HBRBACKGROUND);
  3740. #else
  3741.         hBrushRet=(HBRUSH)::GetClassWord(m_hWnd,GCW_HBRBACKGROUND);
  3742. #endif
  3743.     if(!hBrushRet)
  3744.         hBrushRet = (HBRUSH)::GetStockObject(WHITE_BRUSH);
  3745.  
  3746.     if(ms_bTextColor)
  3747.         ::SetTextColor(hDC,ms_TextColorRef);
  3748.  
  3749.     if(ms_bBkColor)
  3750.         ::SetBkColor(hDC,ms_BkColorRef);
  3751.  
  3752.     if(ms_bBkMode)
  3753.         ::SetBkMode(hDC,ms_fnBkMode);
  3754.  
  3755. #ifdef WIN32
  3756.     return (LRESULT)hBrushRet;
  3757. #else
  3758.     return MAKELONG(hBrushRet,0);
  3759. #endif
  3760. }
  3761.  
  3762.  
  3763. IMPLEMENT_DYNCREATE(CSimCustom, CWnd)
  3764.  
  3765. BEGIN_MESSAGE_MAP(CSimCustom, CWnd)
  3766.  
  3767.    ON_REGISTERED_MESSAGE(wPrivateMessage,SimHandlePrivateMessage)
  3768.  
  3769. END_MESSAGE_MAP()
  3770.  
  3771.  
  3772.  
  3773. // *************************************************************
  3774. // Member function for Class : CSimGraphicButton
  3775. // Base Class                : CButton
  3776. // *************************************************************
  3777.  
  3778. CSimGraphicButton::CSimGraphicButton()
  3779.   : CButton()
  3780. {
  3781.     ms_szBitmap  = NULL;
  3782.     ms_szNormal  = NULL;
  3783.     ms_szFocus   = NULL;
  3784.     ms_szSelected= NULL;
  3785.     ms_szDisabled= NULL;
  3786.     ms_bHidden = FALSE;
  3787. }
  3788.  
  3789.  
  3790. CSimGraphicButton::~CSimGraphicButton()
  3791. {
  3792.     ClearData();
  3793. }
  3794.  
  3795.  
  3796.  
  3797. void CSimGraphicButton::ClearData()
  3798. {
  3799.     if(ms_szBitmap)
  3800.         delete ms_szBitmap;
  3801.     if(ms_szNormal)
  3802.         delete ms_szNormal;
  3803.     if(ms_szFocus)
  3804.         delete ms_szFocus;
  3805.     if(ms_szSelected)
  3806.         delete ms_szSelected;
  3807.     if(ms_szDisabled)
  3808.         delete ms_szDisabled;
  3809.     ms_szBitmap  = NULL;
  3810.     ms_szNormal  = NULL;
  3811.     ms_szFocus   = NULL;
  3812.     ms_szSelected= NULL;
  3813.     ms_szDisabled= NULL;
  3814. }
  3815.  
  3816.  
  3817.  
  3818. void CSimGraphicButton::SimSetGraphicData(char * szBitmap,BOOL bBitmap,BOOL bStretch)
  3819. {
  3820.     ClearData();
  3821.     ms_iGraphicType = SIM_GRAPHIC;
  3822.     ms_szBitmap = new char[lstrlen(szBitmap)+1];
  3823.     if(ms_szBitmap)
  3824.         lstrcpy(ms_szBitmap,szBitmap);
  3825.     ms_bBitmap = bBitmap;
  3826.     ms_bStretch = bStretch;
  3827. }
  3828.  
  3829.  
  3830.  
  3831. void CSimGraphicButton::SimSetGraphicDataBkGrnd(char * szBitmap,BOOL bBitmap,BOOL bStretch)
  3832. {
  3833.     ClearData();
  3834.     ms_iGraphicType = SIM_GRAPHIC_BKGRND;
  3835.     ms_szBitmap = new char[lstrlen(szBitmap)+1];
  3836.     if(ms_szBitmap)
  3837.         lstrcpy(ms_szBitmap,szBitmap);
  3838.     ms_bBitmap  = bBitmap;
  3839.     ms_bStretch = bStretch;
  3840. }
  3841.  
  3842.  
  3843. void CSimGraphicButton::SimSetGraphicData3D(char *szNormal,char *szFocus,char *szSelected,
  3844.          char *szDisabled,BOOL bBitmap,BOOL bStretch)
  3845. {
  3846.     ClearData();
  3847.     ms_iGraphicType = SIM_GRAPHIC_3D;
  3848.     ms_szNormal   = new char[lstrlen(szNormal)+1];
  3849.     if(ms_szNormal)
  3850.         lstrcpy(ms_szNormal,szNormal);
  3851.     ms_szFocus    = new char[lstrlen(szFocus)+1];
  3852.     if(ms_szFocus)
  3853.         lstrcpy(ms_szFocus,szFocus);
  3854.     ms_szSelected = new char[lstrlen(szSelected)+1];
  3855.     if(ms_szSelected)
  3856.         lstrcpy(ms_szSelected,szSelected);
  3857.     ms_szDisabled = new char[lstrlen(szDisabled)+1];
  3858.     if(ms_szDisabled)
  3859.         lstrcpy(ms_szDisabled,szDisabled);
  3860.     ms_bBitmap = bBitmap;
  3861.     ms_bStretch = bStretch;
  3862. }
  3863.  
  3864.  
  3865.  
  3866. void CSimGraphicButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  3867. {
  3868.     switch(ms_iGraphicType)
  3869.         {
  3870.     case SIM_GRAPHIC:
  3871.         if (lpDrawItemStruct->itemAction!=ODA_DRAWENTIRE)
  3872.             return;
  3873.         if(ms_bBitmap)
  3874.             BLDDrawBitmap(lpDrawItemStruct,ms_szBitmap,ms_bStretch);
  3875.         else
  3876.             BLDDrawIcon(lpDrawItemStruct,ms_szBitmap);
  3877.         break;
  3878.     case SIM_GRAPHIC_3D:
  3879.         if(ms_bBitmap)
  3880.             BLDDrawStateBitmap(lpDrawItemStruct,ms_szNormal,ms_szFocus,ms_szSelected,ms_szDisabled,ms_bStretch);
  3881.         else
  3882.             BLDDrawStateIcon(lpDrawItemStruct,ms_szNormal,ms_szFocus,ms_szSelected,ms_szDisabled);
  3883.         break;
  3884.         }
  3885. }
  3886.  
  3887.  
  3888.  
  3889. LRESULT CSimGraphicButton::SimHandlePrivateMessage(WPARAM wParam,LPARAM lParam)
  3890. {
  3891.     LPPAINTSTRUCT lpps;
  3892.  
  3893.     if(ms_iGraphicType != SIM_GRAPHIC_BKGRND)
  3894.         return FALSE;
  3895.     if(wParam != SIM_CTRLPAINT)
  3896.         return FALSE;
  3897.  
  3898.     if(!ms_bHidden)
  3899.         {
  3900.         ShowWindow(SW_HIDE);
  3901.         ms_bHidden=TRUE;
  3902.         }
  3903.     lpps = (LPPAINTSTRUCT)lParam;
  3904.     if(ms_bBitmap)
  3905.         BLDDrawBkgndBitmap(GetParent()->GetSafeHwnd(),lpps,ms_szBitmap,GetDlgCtrlID(),ms_bStretch,TRUE,0,0);
  3906.     else
  3907.         BLDDrawBkgndIcon(GetParent()->GetSafeHwnd(),lpps,ms_szBitmap,GetDlgCtrlID());
  3908.     return TRUE;
  3909. }
  3910.  
  3911.  
  3912.  
  3913. IMPLEMENT_DYNCREATE(CSimGraphicButton, CButton)
  3914.  
  3915. BEGIN_MESSAGE_MAP(CSimGraphicButton, CButton)
  3916.  
  3917.    ON_REGISTERED_MESSAGE(wPrivateMessage,SimHandlePrivateMessage)
  3918.  
  3919. END_MESSAGE_MAP()
  3920.  
  3921.